Loading, please wait...

A to Z Full Forms and Acronyms

Learn Python : VS Code - Part 1

Jul 29, 2018 vscode, python, 3594 Views
In this era of the diversity in latest technology and the ability to learn and be equipped in languages is the most challenging and interesting thing for a developer or a geek you can say. Me being a .Net developer found it interesting personally to get started with the Python, an open source programming language using the Microsoft IDE, the latest one i.e. Visual Studio Code. There are many reasons to choose & learn Python as my choice out of the box , now since Machine learning is the new latest!! :D Python is the best programming language and light weight to be used. I again say it is my personal choice to choose Python. :P Much of talks now, lets get started with what Python is actually and some facts about Python.

Introduction

In this era of the diversity in latest technology and the ability to learn and be equipped in languages is the most challenging and interesting thing for a developer or a geek you can say. Me being a .Net developer found it interesting personally to get started with the Python, an open source programming language using the Microsoft IDE, the latest one i.e. Visual Studio Code. There are many reasons to choose & learn Python as my choice out of the box , now since Machine learning is the new latest!! :D Python is the best programming language and light weight to be used. I again say it is my personal choice to choose Python. :P Much of talks now, lets get started with what Python is actually and some facts about Python.

Python??

An interpreted language which obviously follows object oriented principles. Now much of technicality to be discussed when technical terms are being used. Now as of now, I knew C# (Programming Language) is interpreted into byte code and then is compiled by the Common Language Runtime where as Python is completely interpreted language, which means it is executed directly at the run time unlike the compiled language, which first gets compiled into the assembly language which any CPU can understand.
Python is considered as one of the best Rapid Application Development programming language. It is easy so far for me to learn Python though it is just the beginning. It's semantics are diversified, that is it makes easy as well as strict for the developers to follow coding convention. The indentation is a part of its syntax and the semantics are modular which makes it rather more convenient for the developers to maintain the code.

Setting up Python

Here, I would be sharing the process to set up Python on Windows. First of all check if Python is pre installed on your system. To check that, open Command Prompt and type python. If the output is not desirable i.e. 'python' is not recognized, then it is not installed in that path. To download and install python, click on the below link and download:
Download Python for windows
Now once downloaded, install the Python file in .msi extension in a path and navigate to the same path in command prompt and type python then. This output would be python with the version installed and we are ready to write our first Hello World program and follow the tradition . :D
But before that one of the important things to be done is setting up the environment variables or the system path. This is mainly required in UNIX and Windows because the OS searches for the executable in the specified path in the environment variables set. In Macintosh, the path is handled by the installer. Thus, below the images would guide to set the variables.
                                                                 
Now all set for the python to run on Windows Command Prompt with the first Hello World program.
                                                           
To develop applications using python we would surely need python IDE. There would be many in the market, but yes after being obsessed with the Microsoft products, I prefer to use the open source IDE by MS, Visual Studio Code

Get started with Visual Studio Code

To start with after setting up Python on windows, we need to install the Python extension for Visual Studio Code.
Once installed the extension of Python for the Visual Studio code, open Visual Studio Code and Go to Files->Preferences->Settings. Once navigated, user settings window pops up. Once you see this window,
                                                   
Search for the "python.pythonPath"
There would be Default Settings for the variable, now change the path to the installed folder path on your system.

    //Default settings 
           // Path to Python, you can use a custom version of Python by modifying this setting to include the 
           full path.
          "python.pythonPath": "python"

Path changed under User settings to:

//User Settings
        {
    "python.pythonPath": "C:\\Python27\\python.exe"
        }

         

                               
Now all set to run the any application on the Visual Studio Code in Python. In the IDE terminal below, type python, output is as below:

When we navigate to the Extensions, we can see Python is enabled, with the Linting, Debugging extension. These are used for Intellisense, for which I love Visual Studio. :D
Also there are few modules/packages which are kind of third party but can be used as these are all open source. Just like in .Net we have Nuget Package Manager. So in the terminal itself of the IDE we can install any modules of python like with the below command:
> python -m pip install httppie

The above was one of the examples. The detailed discussion is out of this article's scope. We will discuss in upcoming articles of this series.
Now lets without wasting much time, create a small program in Python and execute to see the output.

class Car(object):
	"""
		blueprint for car
	"""
	def __init__(self, model, color, company, speed_limit):
		self.color = color
		self.company = company
		self.speed_limit = speed_limit
		self.model = model

	def start(self):
		print("started")
maruti = Car("Ertiga","White","Maruti Suzuki",140)
maruti.start()

This is a simple program where we have a class named Car with a method as start that prints "started". More about the properties and constructor in the next article.
maruti is the object instantiated and then the method start() is invoked through it.
Thus, debugging this will give the output "started".

Conclusion

Next we will discuss the details and basics of Python in the upcoming articles of this series.

A to Z Full Forms and Acronyms

Related Article