Introduction To Python

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

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.

Estimated time needed: 40 minutes

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?

Programming helps to simplify/automate many time-consuming tasks and eliminates


human errors.

Let us understand with some real examples about how computer programming has
changed our lives in the last 15 years.

4.1.1 Booking Railway Tickets


Before computers, you had to manually fill up reservation forms, stand in long queues
as the ticketing staff checked for availability and issuance of ticket or processed your
request for cancellation.

With the advent of computer programming, booking/cancelling tickets have become


easier and can be done from the comforts of your home.

4.1.2 Online Transferring of Amount


Before computers, transferring money from one person to another was a long-drawn
process. As this included, the payer going to the bank for the DD and giving it to the
receiver. The receiver then submitted the DD to the bank, and after it cleared, took out
the money by filling out a withdrawal form.

With computer programming, you can instantly transfer money to anyone, and can
withdraw the same from any ATM.

4.2 What is Programming?

Programming helps to construct a series of instructions that computers use to


perform specific tasks or illustrate desired behaviors.

This source code (such as C++, Java, C#, Python etc.) is written in one or more
programming languages.
4.3 History of Python

Python is a successor to ABC programming language. It is capable of handling


exceptions and interfacing with the operating system of Amoeba.

the late 1980s,


Python was created The latest release
at CWI in the was in December
Netherlands by 2020 with the
Guido van Rossum version Python 3.9.1

In 1991, The initial


version of Python
1.X was first
released

4.4 What is Python?

Python is a programming language that is interpreted, interactive, object-oriented,


high-level, and free and open source. Its source code is available under GNU General
Public License (GPL).

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

5.1.1 REPL-Interactive Mode

REPL is called as Read – Eval – Print – Loop

5.1.2 REPL-Script mode

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

Let us look at the indentation rules while using Python.


For instance:

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

# Write the code below

Output

You have completed Python Introduction hands-on exercises in Introduction to


Python.
Copyright © 2021 Accenture
All rights reserved.
Accenture and its logo are trademarks of Accenture.

You might also like