Unit-2
Python Data, Expressions and Statements
Python interpreter and interactive mode –
values and types:-
variables
expressions
statements
tuple assignment
precedence of operators
comments –
modules and functions
function definition and use
flow of execution
parameters and arguments
INTRODUCTION TO PYTHON
Python is a general-purpose interpreted,
interactive, object-oriented, and highlevel
programming language.
It was created by Guido van Rossum during 1985-
1990.
Python got its name from “Monty Python’s flying
circus”. Python was released in the year 2000.
Python is interpreted: Python is processed at
runtime by the interpreter. You do not need to
compile your program before executing it.
Python is Interactive: You can actually sit at a
Python prompt and interact with the interpreter
directly to write your programs.
Python is Object-Oriented: Python supports
Object-Oriented style or technique of
programming that encapsulates code within
objects.
Python is a Beginner's Language: Python is a
great language for the beginnerlevel programmers
and supports the development of a wide range of
applications.
Python features
Easy-to-learn: Python is clearly defined and
easily readable. The structure of the program is
very simple. It uses few keywords.
Easy-to-maintain: Python's source code is fairly
easy-to-maintain.
Portable: Python can run on a wide variety of
hardware platforms and has the same interface
on all platforms.
Interpreted: Python is processed at runtime by the
interpreter. So, there is no need to compile a program
before executing it. You can simply run the program.
Extensible: Programmers can embed python within their
C,C++,Java script ,ActiveX, etc.
Free and Open Source: Anyone can freely distribute it,
read the source code, and edit it.
High Level Language: When writing programs,
programmers concentrate on solutions of the current
problem, no need to worry about the low level details.
Scalable: Python provides a better structure and support
for large programs than shell scripting.
Applications of python
Bit Torrent file sharing
Google search engine, Youtube
Intel, Cisco, HP, IBM
i–Robot
NASA
Python interpreter
Interpreter: To execute a program in a
high-level language by translating it one
line at a time.
Compiler: To translate a program written
in a high-level language into a low-level
language all at once, in preparation for
later execution.
compiler interpreter
Compiler Takes Entire program as Interpreter Takes Single instruction as
input input.
Intermediate Object Code is No Intermediate Object Code is
Generated. Generated.
Conditional Control Statements are Conditional Control Statements are
Executes faster. Executes slower.
Memory Requirement is More(Since Memory Requirement is Less
Object Code is Generated) .
Program need not be compiled every Every time higher level program is
time. converted into lower level program.
Errors are displayed after entire Errors are displayed for every
program is checked. instruction interpreted (if any) .
Example : C Compiler Example : PYTHON.