Introduction To Python
Introduction To Python
Introduction To Python
Python Introduction
Hands-on Exercise
Index
1 Objectives ........................................................................................... 3
2 Overview ............................................................................................. 4
3 Prerequisites ....................................................................................... 5
4 Preliminary Concepts .......................................................................... 6
4.1 Why Do We Need Programming? .................................................................. 6
4.1.1 Booking Railway Tickets..................................................................... 6
4.1.2 Online Transferring of Amount............................................................ 6
4.2 What is Programming?................................................................................... 6
4.3 History of Python............................................................................................ 7
4.4 What is Python? ............................................................................................. 7
4.5 Extensive Library ........................................................................................... 9
5 Guided Exercise: Python Installation................................................ 10
5.1 REPL in Python ........................................................................................... 11
5.1.1 REPL-Interactive Mode .................................................................... 11
5.1.2 REPL-Script mode............................................................................ 11
5.2 Indentation in Python ................................................................................... 12
6 Practice Exercise .............................................................................. 14
1 Objectives
After completing the hands-on exercise, you will be able to:
– Discuss various features of Python
– Demonstrate Python3 installation with various aspects
– Describe the importance of REPL (Read, Evaluate, Print, Loop), whitespaces
and comments in Python
2 Overview
This document provides information about Python programming – definition, history,
uses and libraries. It also consists of guided exercises on Python installation, REPL
and indentation in Python and a practice exercise at the end.
Note: The links provided in the document navigate to the respective web sources and
open in the same window. The users can use the back arrow in the browser, which
navigates back to the beginning of the document.
3 Prerequisites
1. Visit the edX website and check the reference videos on Your First Program
4 Preliminary Concepts
4.1 Why Do We Need Programming?
Let us understand with some real examples about how computer programming has
changed our lives in the last 15 years.
With computer programming, you can instantly transfer money to anyone, and can
withdraw the same from any ATM.
This source code (such as C++, Java, C#, Python etc.) is written in one or more
programming languages.
4.3 History of Python
The source code is executed line by line, and not all at once, so it is easier to debug
the code. Much like PERL/PHP, the interpreter processes Python at runtime. By
interactive it means, you can write valid Python statements directly on the Python
prompt. You can further write object-oriented code in Python by enforcing all object-
oriented programming principles.
As compared to other common languages such as Java and C++, Python is simple,
highly readable, and very easy to code. Python programming uses fewer lines of code
for writing compared to other languages.
Python is a portable language, meaning it can run on any platform. For example, if
we have Python code for Windows, other platforms, such as Linux, Unix, and Mac,
can run the same code without changing it.
Python code can be extended to syntax and compilation in C or C++ and Java.
Similarly, syntax and compilation in C or C++ and Java can also be applied to
Python code.
4.5 Extensive Library
One of the key benefits of Python is that it has an extensive library with built-in modules
which can be used in various applications, such as GUI programming, games, Web
development, Testing, Big Data, AI, and Machine Learning.
AI and Machine Learning have evolved at a very rapid pace in the last few years. This
is due to the introduction of libraries like Numpy, Pandas, Matplotlib, Scipy, Keras and
others. As a result, it is no longer difficult to implement the ML/DL model.
5 Guided Exercise: Python
Installation
The key versions of Python are Python 2.X and Python 3.X
Python 2.X is a legacy version since the last major update of the 2.X series was Python
2.7.2. This was released on June 11th, 2011.
The Python Software Foundation does not support Python 2.X anymore, effective
January 1st, 2020.
Python 3.X is the latest and future version of the language. On December 3rd, 2008,
Python 3.0 (also called "Python 3000" or "Py3K") was released. It was intended to fix
fundamental design defects in the language. Making necessary improvements while
maintaining complete backward compatibility with the 2.X series was becoming
difficult.
You can download the latest version of Python from https://www.python.org/. The
version may vary when you are downloading.
Or,
You can download from Anaconda which is the home to thousands of libraries and
open-source packages related to data science and machine learning.
5.1 REPL in Python
You can also write Python programs in a file and save it with .py extension and
execute it using the Python interpreter.
a. Create a file name firstprogram.py using a text editor with the following content
print(3 + 7)
b. Click Save to execute the program. You must tell the script name to the
interpreter
5.2 Indentation in Python
for i in range(1,6):
print(i)
if i == 3:
break
6 Practice Exercise
Open a new Jupyter notebook and execute the following expressions:
2+7
13 * 7
print(“I am learning python”)
22 / 2
45 / 4
15 * 6.2
Output