Introduction
In this era of diversity in the latest technology, 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, I found it interesting personally to get started with 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 newest! Python is the best programming language and lightweight to use. I again say it is my personal choice to choose Python. Enough talk, let's get started with what Python actually is and some facts about Python.
Python
It's an interpreted language which obviously follows object-oriented principles. Now, a lot of technical terms are being used. As of now, I know C# (Programming Language) is interpreted into bytecode and then is compiled by the Common Language Runtime whereas Python is a completely interpreted language, which means it is executed directly at the runtime 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 languages. It is easy so far for me to learn Python though it is just the beginning. Its semantics are diversified, that is, it makes easy as well as strict for the developers to follow the 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 to 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 with
.msi extension in a path and navigate to the same path in command prompt and type python there. This output would show Python with the version installed and we are ready to write our first Hello World program and follow the tradition.
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, the below images would guide to set the variables.
Now, we are all set for 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 Microsoft, 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 the Visual Studio Code. Once the extension of Python for the Visual Studio code is installed, open Visual Studio Code and go to Files->Preferences->Settings. Once navigated, the 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 is changed under User Settings too.
- //User Settings
- {
- "python.pythonPath": "C:\\Python27\\python.exe"
- }
Now, we are all set to run any application on the Visual Studio Code in Python. In the IDE terminal below, type python; the output is as below.
When we navigate to the Extensions, we can see Python is enabled, with the Linking, Debugging extension. These are used for IntelliSense, the reason I love Visual Studio. Also, there are a 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, let's go ahead without wasting much time. Create a small program in Python and execute that to see the output.
- class Car(object):
-
-
-
- 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". We will learn 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.