If you are new to Python, it is advised to get yourself familiar with features of Python language by trying out one of the online Python interpreters. Once you get acquainted with syntax and other features, you can proceed to install Python environment in your local machine.
One of the easiest ways to start the online Python session is available on Python’s official website’s homepage. Just click on >_ button which opens Python shell powered by http://www.pythonanywhere.com.
The console screen shows >>> symbol called Python prompt where any Python expression can be entered. It will be executed as you press Enter.
Online Python shells work on the principle of REPL (Read, Evaluate, Print, Loop). Another example of online Python REPL is provided by https://repl.it/languages/python3 and it can be used in interactive as well as scripting mode.
Trinket (https://trinket.io/python) is another convenient way to try Python code online.
The right hand column switches between interactive console and output screen of Python script in left column.
Official distribution of Python is available for installation on https://www.python.org/downloads/. As mentioned earlier, two branches of Python versions (Python 2.x and Python 3.x) are available here. Python Software Foundation intends to support bug fixes in Python 2.7.x only till January 1, 2020. Currently Python’s latest versions in both branches are Python 2.7.15 and Python 3.7.0. We shall see installation procedure of Python for different operating system environments.
The download page hosts pre-compiled binaries of web based and standalone installers. Web based installers need live internet connection. Standalone installers on the other hand have complete distribution of Python packaged in it. Different installers for 32 bit and 64 bit architecture are available on download link. If the firewall of your OS doesn’t allow the executable installers, there are embeddable zip file for both platforms.
|x86 web-based installer||https://www.python.org/ftp/python/3.7.0/python-3.7.0-webinstall.exe|
|x86 executable installer||https://www.python.org/ftp/python/3.7.0/python-3.7.0.exe|
|Windows x86 embeddable zip file||https://www.python.org/ftp/python/3.7.0/python-3.7.0-embed-win32.zip|
|x86-64 web-based installer||https://www.python.org/ftp/python/3.7.0/python-3.7.0-amd64-webinstall.exe|
|x86-64 executable installer||https://www.python.org/ftp/python/3.7.0/python-3.7.0-amd64.exe|
|x86-64 embeddable zip file||https://www.python.org/ftp/python/3.7.0/python-3.7.0-embed-amd64.zip|
Using executable installer is the easiest way to install Python. Choose appropriate version of installer as per your hardware and follow the steps of wizard. For most users choosing default settings should be sufficient. Adding installation folder to PATH environment variable of operating system is recommended.
Most distributions of Linux operating system have Python included. If not (or if you want to install other version of Python in addition to the one already available), choose the respective package manager utility. For example in case of Ubuntu Linux, apt-get package manager is executed from command line inside Linux terminal window as follows:
$ sudo apt-get update $ sudo apt-get install python3.7
If you get the output similar to above screen shot, it means Python has been properly installed in your computer!Start Python interpreter from command prompt terminal. The Python prompt with three greater than symbols (>>>) appears. Type and valid Python expression in front of prompt and press Enter. Next line shows the result.
The >>> prompt allows you to use Python interpreter in interactive mode. Type quit() to exit the interactive mode.
It can also be used in scripting mode as explained below:
Open any text editor (such as Notepad), type and save following text as hello.py
x=2 y=3 print (2+3) print ("Hello World!")
Open the command prompt terminal as before and issue following command. You Python script will be executed. You should get following display:
In addition to standard distribution available at https://www.python.org/download, many other third party distributions are available. These distributions often provide a bundle of packages required for a specific application for example scientific computing, machine learning etc. Some of the well known Python distributions are:
Anaconda : https://www.anaconda.com/download/.
ActivePython : http://www.activestate.com/activepython/
In addition to Python Jupyter notebook application also supports other languages like Julia and R. (Jupyter stands for JUlia, PYThon and R).
If you are not willing to use Anaconda distribution, Jupyter notebook can still be installed in the standard distribution using pip utility. Following command will install Jupyter application.
pip3 install jupyter
If you have installed Anaconda distribution, start Jupyter notebook from Anaconda navigator. You can also start it from command prompt (conda prompt if using Anaconda distribution) as follows:
Jupyter notebook is a client-server application. Server is deployed on local host’s default port 8888 and client is opened in a browser window as shown below:
Start a new notebook by choosing Python 3 kernel from the drop down as shown:
The notebook shows input cell. Type a Python statement and run the cell. Output is displayed in output cell below it. Notebook interface allows cell to be deleted, copied, moved etc. The cell can also store markdown text which can be formatted suitably.