top

Search

Python Tutorial

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.Try Python onlineOne 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.InstallationOfficial 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.Installation on WindowsThe 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 installerhttps://www.python.org/ftp/python/3.7.0/python-3.7.0-webinstall.exex86 executable installerhttps://www.python.org/ftp/python/3.7.0/python-3.7.0.exeWindows x86 embeddable zip filehttps://www.python.org/ftp/python/3.7.0/python-3.7.0-embed-win32.zipx86-64 web-based installerhttps://www.python.org/ftp/python/3.7.0/python-3.7.0-amd64-webinstall.exex86-64 executable installerhttps://www.python.org/ftp/python/3.7.0/python-3.7.0-amd64.exex86-64 embeddable zip filehttps://www.python.org/ftp/python/3.7.0/python-3.7.0-embed-amd64.zipUsing 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.7If 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.pyx=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:Anaconda distributionIn addition to standard distribution available at https://www.python.org/downloads/, 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/distribution/.Canopy : https://assets.enthought.com/downloads/ActivePython : https://www.activestate.com/activepython/Anaconda is one of the most Python distributions. It is a full Python package consisting of libraries needed for mathematical and scientific computing. It consists of a large number of data science libraries with its own package management system called conda. It includes a browser based interface to Python interpreter called Jupyter notebook. It allows the user to include formatted text, static and dynamic visualizations, mathematical equations, JavaScript widgets etc. along with Python code. Jupyter notebook document can be exported to PDF, Python script or HTML.In addition to Python Jupyter notebook application also supports other languages like Julia and R. (Jupyter stands for JUlia, PYThon and R).Jupyter notebookIf 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 jupyterIf 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:C:\Users\acer>jupyter notebookJupyter 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.
logo

Python Tutorial

Python - Getting Started

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.

Try Python online

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.

Python code

The console screen shows >>> symbol called Python prompt where any Python expression can be entered. It will be executed as you press Enter.

Python code

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.

Python code

Trinket (https://trinket.io/python) is another convenient way to try Python code online.

Python code

The right hand column switches between interactive console and output screen of Python script in left column.

Installation

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.

Installation on Windows

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 installerhttps://www.python.org/ftp/python/3.7.0/python-3.7.0-webinstall.exe
x86 executable installerhttps://www.python.org/ftp/python/3.7.0/python-3.7.0.exe
Windows x86 embeddable zip filehttps://www.python.org/ftp/python/3.7.0/python-3.7.0-embed-win32.zip
x86-64 web-based installerhttps://www.python.org/ftp/python/3.7.0/python-3.7.0-amd64-webinstall.exe
x86-64 executable installerhttps://www.python.org/ftp/python/3.7.0/python-3.7.0-amd64.exe
x86-64 embeddable zip filehttps://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.

Python code

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:Python code

Anaconda distribution

In addition to standard distribution available at https://www.python.org/downloads/, 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/distribution/.

Canopy : https://assets.enthought.com/downloads/

ActivePython : https://www.activestate.com/activepython/

Anaconda is one of the most Python distributions. It is a full Python package consisting of libraries needed for mathematical and scientific computing. It consists of a large number of data science libraries with its own package management system called conda. It includes a browser based interface to Python interpreter called Jupyter notebook. It allows the user to include formatted text, static and dynamic visualizations, mathematical equations, JavaScript widgets etc. along with Python code. Jupyter notebook document can be exported to PDF, Python script or HTML.

In addition to Python Jupyter notebook application also supports other languages like Julia and R. (Jupyter stands for JUlia, PYThon and R).

Jupyter notebook

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:

C:\Users\acer>jupyter notebook

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:Python code

Start a new notebook by choosing Python 3 kernel from the drop down as shown:Python code

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Comments

Eula

This is my first time here. I am truly impressed to read all this in one place.

Jaypee Dela Cruz

Thank you for your wonderful codes and website, you helped me a lot especially in this socket module. Thank you again!

lucky verma

Thank you for taking the time to share your knowledge about using python to find the path! Your insight and guidance is greatly appreciated.

Pre Engineered Metal Building

Usually I by no means touch upon blogs however your article is so convincing that I by no means prevent myself to mention it here.

Pre Engineered Metal Building

Usually, I never touch upon blogs; however, your article is so convincing that I could not prevent myself from mentioning how nice it is written.

Suggested Tutorials

Swift Tutorial

Introduction to Swift Tutorial
Swift Tutorial

Introduction to Swift Tutorial

Read More

R Programming Tutorial

R Programming

C# Tutorial

C# is an object-oriented programming developed by Microsoft that uses the .Net Framework. It utilizes the Common Language Interface (CLI) that describes the executable code as well as the runtime environment. C# can be used for various applications such as web applications, distributed applications, database applications, window applications etc.For greater understanding of this tutorial, a basic knowledge of object-oriented languages such as C++, Java etc. would be beneficial.
C# Tutorial

C# is an object-oriented programming developed by Microsoft that uses ...

Read More