CHAPTER-5
[Getting Started
with Python]
Name derived from famous BBC
comedy show namely Monty
Python‟s flying circus
Prepared by:
VIJAYCHAWLA, PGT CS,
KV PITAMPURA,
DELHI – 110034
CHAPTER 1
GETTING STARTED WITH PYTHON
It is widely used general purpose, high level programming
language.
Python is a programming language that lets you work quickly
and integrate systems more effectively.
Python was created by Guido Van Rossum
The language was released in February I991
Python got its name from a BBC comedy series from seventies-
“Monty Python‟s Flying Circus”
Python can be used to follow both Procedural approach and
Object Oriented approach of programming
It is OSS , free to use and can be freely downloaded from
www.python.org/downloads
INTRODUCTION
Python is a high-level, interpreted and general-
purpose dynamic programming language that
focuses on code readability. The syntax in Python
helps the programmers to do coding in fewer steps
as compared to Java or C++.
The language founded in the year 1991 by the
developer Guido Van Rossum has the programming
easy and fun to do.
Where does the Python name come from?
When he began
implementing Python, Guido van
Rossum was also reading the published
scripts from “Monty Python's Flying
Circus”, a BBC comedy series from the
1970s. Van Rossum thought he needed a
name that was short, unique, and
slightly mysterious, so he decided to call
the language Python.
WHY COMPANIES PREFER PYTHON?
WHY COMPANIES PREFER PYTHON?
Python has top the charts in the recent years
over other programming languages like C, C++
and Java and is widely used by the programmers.
The language has undergone a drastic change
since its release 25 years ago as many add-on
features are introduced. The Python 1.0 had the
module system of Modula-3 and interacted with
Amoeba Operating System with varied
functioning tools. Python 2.0 introduced in the
year 2000 had features of garbage collector and
Unicode Support.
WHY COMPANIES PREFER PYTHON?
Python 3.0 introduced in the year 2008 had a
constructive design that avoids duplicate
modules and constructs. With the added
features, now the companies are using Python
3.10.
The software development companies prefer
Python language because of its versatile features
and fewer programming codes. Nearly 14% of
the programmers use it on the operating systems
like UNIX, Linux, Windows and Mac OS.
WHY COMPANIES PREFER PYTHON?
The programmers of big companies use Python
as it has created a mark for itself in the software
development with characteristic features like:
Interactive
Interpreted
Modular
Dynamic
Object-oriented
Portable
High level
Extensible in C++ & C
WHY COMPANIES PREFER PYTHON?
The programmers of big companies use Python
as it has created a mark for itself in the software
development with characteristic features like:
Easy-to-learn
Easy-to-read
Easy-to-maintain
Robust
Effective as a Rapid Prototyping Tool
A Memory Manager
Interpreted and (Byte-) Compiled
COMPANIES USING PYTHON
COMPANIES USING PYTHON
COMPANIES USING PYTHON
Easy to use Object oriented language
Expressive language
Interpreted Language
Its completeness
Cross-platform Language
Fee and Open source
Variety of Usage / Applications
• Python is compact and very easy to use object oriented
language with very simple syntax rules. It is a high level
language and very programmer-friendly.
• More capable to express code„s purpose than many
other language.
In C++ In Python
int a=2, b=3, tmp; a,b=2,3
tmp=a; a,b=b,a
a=b;
b=tmp; VINOD KUMAR VER MA, PGT(CS), KV OEF KANPUR &
• It is interpreted not compiled, thus executes code line by line
and it makes python easy-to-debug and suitable for beginners
and advanced users
• When you install Python, you get a lot of libraries installed by
default. All functionality is available with Python additional
library. Features like web-pages, database connectivity, GUI
features are available in Python standard library.
• Python can run equally well on variety of platforms – Windows,
Linux/UNIX, Macintosh, supercomputers.
• Python is portable language.
• It is feely available i.e. without any cost can be downloaded
from www.python.org.
• It is also open source i.e. you can modify, improve/extend an
open-source software
Not the fastest language
Lesser Libraries than C, C++, Java, Perl
Not Strong on Type-binding
Not Easily convertible
• Because of its interpreted nature Python is not fast as compare
to compiled language. Python is first compiled into an internal
byte-code which is then executed by Python interpreter.
• Python offers library support for almost all computing
programs, but its library is still not competent with languages
like C, java as they have larger collection available.
• Python is not very strong on data type checking i.e. “Type-
mismatch” issues. For example if you declare variable as
integer but later store a string value in it, Python will not raise
any error.
• Because of its lack of syntax, Python is easy to program but it
becomes disadvantage when it comes to translate python
program to another language.
• Python is being used in many diverse
fields/applications, some of which are:
• Software Development
• Web Applications
• Game Development
• Scientific Computing
• System Administrations
• Scripting/Programming
• GUI Programs
• Database Applications
Installing Python
Two Steps Only –
1. Download Python distribution
2. Python installation process
Installing Python
1. Download Python distribution
Open the link
https://www.python.org/
Note – Download only that python distribution/MSI Installer, which is best suited for
the Operating system on which you want to install it.
Installing Python
1. Download Python distribution
Click on Downloads or directly open the link https://www.python.org/downloads/
Note – Download only that python distribution/MSI Installer, which is best suited for
the Operating system on which you want to install it.
Note that Python 3.9.0 cannot be used on Windows 7 or earlier.
Installing Python
2. Python installation process
1. Double-click the icon labeling the file <version>.exe
Popup window will appear
Installing Python
2. Setup popup window will appear
Installing Python
5. Soon, a new Python <version> Setup pop-up window will
appear with a Setup was successfully message
Click the close button
How to work in Python
PROCESS OF WRITING PROGRAM
After installation of python ,we can work on it in following ways
(i) in Interactive mode
(ii) in Script mode
Before we start working on Python we need to install Python in our
computer. There are multiple distributions available today:
Default Installation available from www.python.org is called
Cpython installation and comes with python interpreter, Python
IDLE(Python GUI) and Pip(package installer)
ANACONDA Python distribution is one such highly
recommended distribution that comes with preloaded many
packages and libraries(NumPy, SciPy, Panda etc)
Other Popular IDEs like Sypder, PyCharm, etc. Spyder IDE is
available as a part of ANACONDA.
After Python installation we can start working with python. In
Python we can work in 2 ways:
Interactive Mode
(Immediate
Python working Mode)
Ways
Script Mode
Interactive modes – one command at a time
Python executes the given command and gives the output.
In interactive mode we type command at IDLE prompt ( >>> )
For e.g if you type 20 + 30 in from of IDLE prompt
>>> 20 + 30 (command give by user)
50 (output given by python)
From the above example you can see than at >>> we have to
just give the command to execute and python we execute it if it
is error free otherwise gives an error.
How to work in Python
Python command
prompt >>>
Type the following at prompt
print “hello”
print 8*3
print 3**3
k=3+4*3
print k
( )
( )
( )
( )
( )
print (“Hello”)
Script Mode – multiple commands can be saved in a file as a
program and then we can execute the entire program
we type Python program in a file and then use the interpreter
to execute the content from the file.
Working in interactive mode is convenient for beginners and for
testing small pieces of code, as we can test them immediately.
But for coding more than few lines, we should always save our
code so that we may modify and reuse the code
In Python IDLE :
Click File New
In new window type the commands you want to save in program
For example:
print(“Hello World!”)
FileSave to save file. Give extension .py to execute it as
python script
Save the
program
and press
F5
( )
Type the below code in script file:
#My First Program
print(“Hello World!”)
When you execute the script file output will be only
Hello World
Note: the first line starts from # which makes line as a
comment i.e. only for programmer information not for
interpreter. Comments are ignored by interpreter
To print or display output Python 3.x provides print() function.
Examples:-
print(“Welcome to Python”)
it will print Welcome to Python
print("Python rocks ! “ )
it will print Python rocks!
Note: Python allows both single quotation and double quotation
to enclose string. In any case both opening and closing must be
same.
print( “ Look carefully „ )
it will give error because both opening and closing
quotes are different.
Note:
1) In Python 2.x print is a statement, not a function
2)Python is case-sensitive i.e. it will treat small letter and
capital letter as two different entities like m & M will be
treated differently in Python.
3)We can use up arrow (↑) and down arrow (↓) to select
previous command and press enter to recall and execute.
4)print statement is required only while working with
script mode otherwise in interactive mode values can be
printed without print statement
#This is my first program
#sample of basic statements
#print(“Watch out”)
print(“Hello World”)
print(“Python Rocks !!!!”)
(a) (b)
This is my first program sample of basic Watch out
statements Hello World
Watch out Python Rocks !!!!
Hello World
Python Rocks !!!!
(c)
(d)
Hello World
This is my first program
Python Rocks !!!!
Hello World
Python Rocks !!!!
• Who developed Python Programming Language?
• Is Python Object Oriented Language?
• Why Python is called an interpreted language?
• What does cross-platform means?
• Python is free and open source. What do you
understand by this feature?
• What is the difference in interactive mode and Script
mode in Python?
Thank You