Getting Started With Python

Introduction

 
The key points covered in this article are,
  • What is Python?
  • Installing Python (on Windows)
  • Installing and using Visual Studio Code for Python development.
  • Woking with IDLE.
  • Visual Studio for Python development.
  • Anaconda Distribution and Jupyter NoteBook.

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.
 
Getting Started with Python
 
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).
 
Getting Started with Python
 
Open command prompt, and type python –version command to check the version of Python installed on the system.
 
Getting Started with Python
 
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. 
 
Getting Started with Python
 

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.
 
Getting Started with Python
 
Now, run the Python Command Line Interpreter with the script name (with ext.) and see the output in the command prompt. 
 
Getting Started with Python
 
Some of the Popular Text Editor available are,
  1. Visual Studio Code
  2. Sublime Text
  3. Atom
  4. 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.
 
Getting Started with Python
 
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. 
 
Getting Started with Python
 
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.
 
Getting Started with Python
 
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.
 
Getting Started with Python
 
The output of the application will be visible in Terminal as well as in debug console.
 
Getting Started with Python
 
Using IDE for the Development: There are several IDE’s available with the Python support. Some of them are listed below,
  1. Visual Studio
  2. PyCharm
  3. Spyder
  4. Thonny etc.
  5. 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.
 
Getting Started with Python
 
You can also execute the Python statements directly just as we did in Python Shell Command prompt. 
 
Getting Started with Python
 
To create a New Script in IDLE, Go to File Menu, and click on New File.
 
Getting Started with Python
 
Type the Python code in it and save it with .py extension.
 
Getting Started with Python
 
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.
 
Getting Started with Python
 

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. 
 
Getting Started with Python
 
In order to demonstrate, I have added some code in PythonApp.py file. Click on run.
 
Getting Started with Python 
 

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) 
 
Getting Started with Python
 
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. 
 
Getting Started with Python
 

Running the Jupyter Notebook

 
Open the Anaconda Navigator, and click on the Launch button in Jupyter Notebook tile.
 
Getting Started with Python
 
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. 
 
Getting Started with Python
 
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. 
 
Getting Started with Python
 

Summary

 
Hope this article will help you in getting started with Python.
 
Thanks.


Similar Articles