About Python (Wikipedia)

Python is an interpreted, high-level, general-purpose programming language. Created by Guido van Rossum and first released in 1991, Python has a design philosophy that emphasizes code readability, notably using significant whitespace. It provides constructs that enable clear programming on both small and large scales.

Python features a dynamic type system and automatic memory management. It supports multiple programming paradigms, including object-oriented, imperative, functional and procedural, and has a large and comprehensive standard library.

Python interpreters are available for many operating systems. CPython, the reference implementation of Python, is open source software.

Interpreted: No need to compile (converting the script into machine readable form) a python script before executing it. The interpreter executes the script directly hiding the low level tasks from the user.

High-level: Strong abstraction from the details of the computer. The user need not know intricate functioning of the computer to write their codes.

General-purpose: Can be applied to wide variety of application domains. The constructs do not restrict python in anyway so that it cannot be used for any particular application.

Dynamic type system: The variables, expressions, functions or modules need not be assigned a type in python. Python is able to take care of the types internally and dynamically during run time. The opposite of a Dynamic type system is a Static type system.

Object-oriented: Allows variables (attributes) and functions (methods) to be bundled into an object.

Imperative programming: It means that each Python statement is a command for the computer to perform.

Functional programming: It is designed on the concept of mathematical functions and does not support state. The functions in functional programming are pure functions as you define functions in Maths. The functions do not change state and only depend on the inputs that are given to them.

Procedural programming: It is a type of imperative programming which contains a list of commands bundled as a procedure, which is also referred to as a subroutine or function.

Writing and Executing Python Codes

Jupyter Notebook

The IPython Notebook, now known as the Jupyter Notebook, is an interactive computational environment, in which you can combine code execution, rich text, mathematics, plots and rich media. The codes can be written and executed directly on a browser. It is like a notebook that contains your codes.

Getting started with Jupyter

For using Jypyter, we will rely on Anaconda installation which is available through the following link:


Anaconda provides a navigator, which is a graphical user interface, for the desktop that allows the launch of various applications for Python and R without using any command-line commands. Anaconda includes Jupyter Notebook as an application within it. Throughout this course, we will be write all our codes on Jupyter notebook.

Terminal (For advanced users)

Python scripts are stored in files with .py extension. Most of the operating systems hide the file extensions from the users. It might be a good idea to enable the file extensions, which can be done as follows:

To view file extension on Windows:
1.  Open Control Panel 
2.  Go to Appearance and Personalization
3.  Click on Folder Options or File Explorer Option
4.  Go to View tab. Under Advanced Settings, you will see the option Hide extensions for known file types
5.  Uncheck this option and click on Apply and OK

To view file extension on Mac:
1.  Open a new Finder window on your Mac
2.  In the Menu bar, go to Finder > Preferences
3.  Click on the Advanced tab
4.  Select the box that says “Show all filename extensions”

Basic commands on Terminal

The command window in Windows is call CMD and in Linux/Mac it is called TERMINAL. The change directory command in Windows or Linux or Mac are as follows:

In [ ]:
>> cd directory/to/path

To go one folder up:

In [ ]:
>> cd ..

Note that file paths in Windows are specified in a different way as compared to Linux or Mac

In [ ]:
Windows: directory1\directory2\filename.py
Mac/Linux: directory1/directory2/filename.py

Python Installation

Check in your command terminal whether python is already installed by writing the following command:

In [ ]:
>> python --version

If the terminal prints python and its version that means you can skip the following steps and go to writing your first python code. If the terminal says that python is not found, then you will have to install python on your computer by downloading python from the following website:


In case python is still not recognized in the terminal window, you will have to add its installation location in the path variable.

Editor for editing the code

Windows, Mac and Linux users can install Visual Studio Code from the following link which is used as an editor for writing and editing your codes (https://code.visualstudio.com/).

You are free to use any other code editor of your choice.

Your first Python script file

Open you code editor and write the following script:

In [ ]:
print('My first command on Python')

Save the file as firstCommand.py in a directory of your choice. Go to the command window and change the directory to the location where the above file is stored using the change directory command and then run the above python file as follows:

In [ ]:
>> python firstCommand.py

Python script on command window

You can even write scripts directly on the command window by going to the python environment. The following command takes you to the python environment:

In [ ]:
>> python

You can write your scripts here directly. To quit the environment you will have to use the command:

In [ ]:
>>> quit()