Introduction to Python,
Installation, Using Interactive
Shell, Creating Saving and
Running Python Script
Presented by
Mohd Shuaib
Assistant Professor
What is Python
• Python is a general purpose programming language applied in scripting
roles.
• So it is a programming language as well as scripting language.
• Python is also called interpreted language.
• A scripting language is a programming language that employs a high-level
construct to interpret and execute one command at a time. In general,
scripting languages are easier to learn and faster to code in than more
structured and compiled languages such as C and C++.
• Compiled languages are converted permanently into executable files
before they are run. In contrast, scripting languages are typically
converted into machine code on the fly during runtime by a program
called an interpreter.
History of Python
• Developed in early 1990’s by Guido van Rossum at Centrum Wiskunde en
Informatica (CWI) is the national research institute for mathematics and
computer science in the Amsterdam, Netherlands then in The Corporation
for National Research Initiatives (CNRI), based in Reston, Virginia.
• Python was conceived in the late 1980s and its implementation was started
in December 1989.
• Guido van Rossum is a fan of “Monty Python’s Flying Circus” this is a
famous TV show in Netherlands.
• Named after Monty Python.
• Open Sourced from the beginning.
• Python is a widely used general-purpose, high level programming language.
• It was created by Guido van Rossum in 1991 and further developed by the
Python Software Foundation.
• It was designed with an emphasis on code readability, and its syntax allows
programmers to express their concepts in fewer lines of code.
• There are two major Python versions: Python 2 and Python 3.
Latest Python 3 Release - Python 3.11.2
Python 3.10.10 - Feb. 8, 2023 Stable
Prerequisites:
Knowledge of any programming language
Reason for increasing popularity:
• Emphasis on code readability, shorter codes, ease of writing
• Programmers can express logical concepts in fewer lines of code in comparison
to languages such as C++ or Java.
• Python supports multiple programming paradigms, like object-oriented,
imperative and functional programming or procedural.
• There exists inbuilt functions for almost all of the frequently used concepts.
• Philosophy is “Simplicity is the best”.
Features
• Interpreted (There are no separate compilation and execution steps)
• Platform Independent
• Free and Open Source
• High-level Language (no need to take care about low-level details such
as managing the memory used by the program)
• Simple
Like English language; Easy to Learn
More importance on the solution to the problem rather than the
syntax
• Embeddable (used with in other programs as scripting language)
• Robust (Built in Exceptional handling and memory mgmt.)
• Rich Library Support
Java Code Python Code
public class HelloWorld print("Hello, world!")
{
public static void main (String[] args)
{
System.out.println("Hello, world!");
}
}
Installing Python in Windows, Linux
and Osx (Apple MacIntosh operating system)
• Python can be installed on Windows, Linux, Mac OS.
• To install Python on your local machine, get a copy of the standard
distribution of Python software from
https://www.python.org/downloads based on your operating system,
hardware architecture and version of your local machine.
Windows
• To install Python on a Windows platform, you need to download the
installer. A web-based installer, executable installer and embeddable zip
files are available to install Python on Windows. Visit
https://www.python.org/downloads/windows and download the
installer based on your local machine's hardware architecture.
• The web-based installer needs an active internet connection. So, you
can also download the standalone executable installer. Visit
https://www.python.org/downloads and click on the Download Python
3.11.2 button as shown below. (3.11.2 is the latest version as of this
writing.)
After successful installation, you can check the Python installation by opening a
command prompt and type python --version or python -V and press Enter. If
Python installed successfully then it will display the installed version.
Mac OS X
You can install Python by downloading official installer from
https://www.python.org/downloads/mac-osx page. Download the
latest version of Python under the heading Python Releases for
Mac OS X. Double click on the installer file to start the
installation wizard.
On the installation wizard, click on Continue a few times until
you're asked to agree to the software license agreement, click
on Agree and finish the installation.
Install Python on Linux
Most of Linux distributions come with Python already installed. However, the
Python 2.x version is incorporated in many of them. To check if Python 3.x is
available, run the following command in the Linux terminal:
$ which python3
If available, it will return the path to the Python3 executable as
/usr/local/bin/python3.
To install Python on Ubuntu 18.04, Ubuntu 20.04 and above, execute the following
commands:
$ sudo apt-get update
$ sudo apt-get install python3.7 python3-pip
After the installation, you can run Python 3.8 and pip3 commands.
Application Areas of Python
Python is used in various types of applications such as
• Data Science,
• Statistical Analysis
• Machine Learning,
• Web Development,
• Image Processing,
• Game Development,
• Embedded Systems and IoT,
• Android Apps, etc.
Where to use Python
Data Science
Python experienced a recent emergence in popularity charts, mainly because of its Data science
libraries. A huge amount of data is being generated today by web applications, mobile applications,
and other devices. Companies need business insights from this data.
Today Python has become the language of choice for data scientists. Python libraries like NumPy,
Pandas, and Matplotlib are extensively used in the process of data analysis, including the
collection, processing and cleansing of data sets, applying mathematical algorithms, and generating
visualizations for the benefit of users. Commercial and community Python distributions by third-
parties such as Anaconda and ActiveState provide all the essential libraries required for data
science.
Machine Learning
This is another key application area of Python. Python libraries such as Scikit-learn, Tensorflow and
NLTK are widely used for the prediction of trends like customer satisfaction, projected values of
stocks, etc. Some of the real-world applications of machine learning include medical diagnosis,
statistical arbitrage, basket analysis, sales prediction, etc.
Web Development
This is another application area in which Python is becoming popular. Web
application framework libraries like django, Pyramid, Flask, etc. make it very
easy to develop and deploy simple as well as complex web applications. These
frameworks are used extensively by various IT companies.
Image Processing
The OpenCV library is commonly used for face detection and gesture
recognition. OpenCV is a C++ library but has been ported to Python. Because of
the rapid development of this feature, Python is a very popular choice from
image processing.
Game Development
Python is a popular choice for game developers. The PyGame library is
extensively used for building games for desktop as well as for mobile platforms.
PyGame applications can be installed on Android too.
Embedded Systems and IoT
Another important area of Python application is in embedded systems.
Raspberry Pi is a very popular yet low-cost single-board computer. It is
extensively used in automation products, robotics, IoT, and kiosk applications.
Popular microcontrollers like Arduino are used in many IoT products and are
being programmed with Python. A lightweight version of Python called
Micropython has been developed, especially for microcontrollers. A special
Micropython-compatible controller called PyBoard has also been developed.
Using Interactive Shell: Shell/REPL
Python is an interpreter language. It means it executes the code line by line.
Python provides a Python Shell, which is used to execute a single Python
command and display the result.
It is also known as REPL (Read, Evaluate, Print, Loop), where it reads the
command, evaluates the command, prints the result, and loop it back to read
the command again.
To run the Python Shell, open the command prompt or power shell on
Windows and terminal window on mac, write python and press enter. A Python
Prompt comprising of three greater-than symbols >>> appears, as shown below.
• Now, you can enter a single statement and get the result. For example,
enter a simple expression like 3 * 2, press enter and it will display the
result in the next line, as shown above.
Execute Python Script
As you have seen above, Python Shell executes a single statement. To
execute multiple statements, create a Python file with extension .py,
and write Python scripts (multiple statements).
For example, enter the following statement in a text editor such as
Notepad.
Save it as first.py, navigate the command prompt to the folder where
you have saved this file and execute the python first.py command, as
shown below. It will display the result.
Python IDLE
• IDLE (Integrated Development and Learning Environment) is an integrated
development environment (IDE) for Python. The Python installer for Windows
contains the IDLE module by default.
• IDLE is not available by default in Python distributions for Linux. It needs to be
installed using the respective package managers. Execute the following command
to install IDLE on Ubuntu:
$ sudo apt-get install idle
IDLE can be used to execute a single statement just like Python Shell and also to
create, modify, and execute Python scripts. IDLE provides a fully-featured text editor
to create Python script that includes features like syntax highlighting,
autocompletion, and smart indent. It also has a debugger with stepping and
breakpoints features.
Python Editors (IDE) Integrated
Development Environment
• Jupyter Notebook(browser based graphical interface to the Ipython
shell) (Jupyter stands for JUlia, PYThon, and R).
pip3 install jupyter
jupyter notebook
The notebook is saved with the .ipynb extension. It can be exported to
HTML or PDF format so that it can be shared.
• Pycharm created by jetbrains (community, professional edition)
• VS Code
• Spyder