What is Python?
Python is a high-level, general-purpose, interpreted, cross-platform, case-sensitive and Object-Oriented programming language. Python was created by Guido van Rossum and first released in around 1991. It uses an Object-Oriented approach which makes the programmer write clear, logical code for the projects. Python has become one of the most popular programming languages used in the world. It is easy to learn because its syntax is similar to the English language, uses the new line to complete the command and indentation to indicate a block of code. Python is derived from C, C++, Algol-68, Unix Shell, and other scripting languages, etc. The latest version of the Python is Python 3.
Many large companies are using the Python language includes Google, YouTube, Netflix, NASA, etc. It is available open-source and available at free of cost. Python is used in Web Development, GUI Application, Scientific and Numeric Computing, Console based applications, Enterprise Application, Data Science and Machine Learning, etc.
Environment Setup
Python can be installed in multiple ways in a system.
You can directly download Python from
here, the official website (as shown in below image). I am downloading Python for Windows Operating System. Python is also available for Mac OS as well as Linux operating system.
On clicking download, a .exe package of size Around 25 M.B. is downloaded. Click on it to start the installation. Make sure to add Python 3.7 to the Path variable (You can also do it manually as well).
Open command prompt, and type python –version command to check the version of Python installed on the system.
Run the Python command line interpreter by typing Python in command prompt and press the enter key. Type Print Function which prints the given object on the Standard output device (Screen) or to the text stream file. For demonstration, I am passing “Hello World” in the print function.
Creating a Python .py file
Open any Text Editor available in the system. For example, In windows, open Notepad. Write the simple print method and save it as MyFirstApp.py.
Now, run the Python Command Line Interpreter with the script name (with ext.) and see the output in the command prompt.
Some of the Popular Text Editor available are,
- Visual Studio Code
- Sublime Text
- Atom
- Vim
Setting Up Visual Studio Code for the Python
Go to
here and download the Visual Code. As I am using the Windows operating system, I will download setup for Windows. Once downloaded, run the installer.
After successful installation, Launch the VS Code, and click on the Extension icon and search extension for Python. Click on "Install".
The extension will help us in providing intelligence, code formatting, snippets and debugging, etc.
Now, open a folder where you want to save the Python code. Then Click on Add new file, give it a meaningful name and then write the Python code in it. I have written a simple code for demonstration.
Click on the Debug icon and then start debugging. As I have created a single Python file, select the currently active Python file as Debug Configuration. In case your application is not started by clicking debug, you need to check the launch.json and settings.json files for the configuration related issues.
The output of the application will be visible in Terminal as well as in debug console.
Using IDE for the Development: There are several IDE’s available with the Python support. Some of them are listed below,
- Visual Studio
- PyCharm
- Spyder
- Thonny etc.
- Idle
Idle
Python (on Windows) comes with IDLE (Integrated Development and Learning Environment) IDE which can also be used for learning purposes. Search IDLE in the Start button search and launch it.
You can also execute the Python statements directly just as we did in Python Shell Command prompt.
To create a New Script in IDLE, Go to File Menu, and click on New File.
Type the Python code in it and save it with .py extension.
Once the file is saved, click on Press F5 to run the module in the Python Shell. On a successful run, Idle will show output something like below.
Python in Visual Studio
Visual Studio 2017 and higher versions support the Python Development. During Installation of the visual studio, select the Python Development Component. I have already installed Python Development Tool in my Visual Studio 2017 IDE. Let’s create a new Python Project (console application) as shown in the below image.
In order to demonstrate, I have added some code in PythonApp.py file. Click on run.
Anaconda Distribution
You can also install Python by installing open source Anaconda Distribution
here which makes it easier to use Python for data science and machine learning on Windows, Linux and Mac OS X. Basically, Once downloaded, click on next and next buttons to install it. (Installation is very simple. During installation it will ask the location to install and also ask to add path environment variables just like we did during Python installation)
Anaconda Distribution provides libraries and tools with Python for data science, machine learning, deep learning, etc. out of the box. It includes core Python language, 100+ Python libraries, Spyder and pycharm which are IDE, and Jupyter Notebook, etc. Search Anaconda Navigator in the start menu and launch it.
Open the Anaconda Navigator, and click on the Launch button in Jupyter Notebook tile.
Basically, it is a web (client-server based) application that runs on localhost on default port 8888. Its UI shows files and folders. You can create a new Jupyter notebook by clicking on New and selecting Python 3 options.
In Jupyter Notebook, you can add cells and, in each cell, you can write code or Markdown as per your need for the documentation purpose. You can execute the code by clicking on the run cell button. The notebook is saved with.ipynb extension. It can also be exported to HTML as well as PDF format as well.
Hope this article will help you in getting started with Python.
Thanks.