Python ppt
Python ppt
PYTHON - An Introduction 1 / 63
Introduction to PYTHON What is PYTHON?
W HAT IS PYTHON?
PYTHON - An Introduction 2 / 63
Introduction to PYTHON What is PYTHON?
W HAT IS PYTHON?
PYTHON - An Introduction 2 / 63
Introduction to PYTHON What is PYTHON?
W HAT IS PYTHON?
PYTHON - An Introduction 2 / 63
Introduction to PYTHON What is PYTHON?
W HAT IS PYTHON?
PYTHON - An Introduction 2 / 63
Introduction to PYTHON History
H ISTORY
PYTHON - An Introduction 3 / 63
Introduction to PYTHON History
H ISTORY
PYTHON - An Introduction 3 / 63
Introduction to PYTHON History
H ISTORY
PYTHON - An Introduction 3 / 63
Introduction to PYTHON History
H ISTORY
PYTHON - An Introduction 3 / 63
Introduction to PYTHON History
H ISTORY
PYTHON - An Introduction 3 / 63
Introduction to PYTHON History
PYTHON - An Introduction 4 / 63
Introduction to PYTHON History
PYTHON - An Introduction 4 / 63
Introduction to PYTHON History
PYTHON - An Introduction 5 / 63
Introduction to PYTHON History
PYTHON - An Introduction 5 / 63
Introduction to PYTHON History
PYTHON - An Introduction 5 / 63
Introduction to PYTHON History
PYTHON - An Introduction 5 / 63
Introduction to PYTHON History
PYTHON - An Introduction 5 / 63
Introduction to PYTHON History
Python is portable: it runs on many Unix variants including Linux and macOS, and on
Windows.
PYTHON - An Introduction 6 / 63
Introduction to PYTHON History
Python is portable: it runs on many Unix variants including Linux and macOS, and on
Windows.
Python includes a comprehensive base library.
PYTHON - An Introduction 6 / 63
Introduction to PYTHON History
Python is portable: it runs on many Unix variants including Linux and macOS, and on
Windows.
Python includes a comprehensive base library.
Addition to this, One can find hundreds of thousands of external packages contributed
by the enormous community. You’ll find supporting base libraries and packages for
pretty much anything you want to accomplish.
PYTHON - An Introduction 6 / 63
Introduction to PYTHON History
PYTHON - An Introduction 7 / 63
Introduction to PYTHON Anaconda
I NTRODUCTION TO A NACONDA
PYTHON - An Introduction 8 / 63
Introduction to PYTHON Anaconda
I NTRODUCTION TO A NACONDA
PYTHON - An Introduction 8 / 63
Introduction to PYTHON Anaconda
I NTRODUCTION TO A NACONDA
PYTHON - An Introduction 8 / 63
Introduction to PYTHON Anaconda
I NTRODUCTION TO A NACONDA
PYTHON - An Introduction 8 / 63
Introduction to PYTHON Anaconda
PYTHON - An Introduction 9 / 63
Introduction to PYTHON Anaconda
A PPLICATIONS IN NAVIGATOR
PYTHON - An Introduction 10 / 63
Introduction to PYTHON Anaconda
J UPYTER N OTEBOOK
PYTHON - An Introduction 11 / 63
Introduction to PYTHON Anaconda
J UPYTER N OTEBOOK
PYTHON - An Introduction 11 / 63
Introduction to PYTHON Anaconda
J UPYTER N OTEBOOK
PYTHON - An Introduction 11 / 63
Introduction to PYTHON Anaconda
J UPYTER N OTEBOOK
PYTHON - An Introduction 11 / 63
Introduction to PYTHON Anaconda
PYTHON - An Introduction 12 / 63
Introduction to PYTHON Anaconda
PYTHON - An Introduction 13 / 63
Introduction to PYTHON Installing Python
PYTHON - An Introduction 14 / 63
Introduction to PYTHON Installing Python
I NSTALLING P YTHON
N OTE :
Python 3.10 supports Windows 8.1 and newer. If you require Windows 7 support, please
install Python 3.8.
PYTHON - An Introduction 15 / 63
Introduction to PYTHON Installing Python
I NSTALLING P YTHON
N OTE :
Python 3.10 supports Windows 8.1 and newer. If you require Windows 7 support, please
install Python 3.8.
For full installation: download “Python 3.10” installer available for download.
The following dialogue box appears.
PYTHON - An Introduction 15 / 63
Introduction to PYTHON Installing Python
PYTHON - An Introduction 16 / 63
Introduction to PYTHON Installing Python
PYTHON - An Introduction 17 / 63
Introduction to PYTHON Installing Python
PYTHON - An Introduction 18 / 63
Introduction to PYTHON Installing Python
PYTHON - An Introduction 19 / 63
Introduction to PYTHON Installing Python
PYTHON - An Introduction 20 / 63
Introduction to PYTHON Installing Python
PYTHON - An Introduction 21 / 63
Introduction to PYTHON INSTALLING PACKAGES FOR PYTHON
PYTHON - An Introduction 22 / 63
Introduction to PYTHON INSTALLING PACKAGES FOR PYTHON
PYTHON - An Introduction 22 / 63
Introduction to PYTHON Shell/Editor
S HELL /E DITOR
S HELL /E DITOR
Open IDLE (Integrated Development and Learning Environment). IDLE shell opens
and one can start working
PYTHON - An Introduction 23 / 63
Introduction to PYTHON Shell/Editor
S HELL /E DITOR
S HELL /E DITOR
Open IDLE (Integrated Development and Learning Environment). IDLE shell opens
and one can start working
Select “New File” from “File” menu.
PYTHON - An Introduction 23 / 63
Introduction to PYTHON Shell/Editor
S HELL /E DITOR
S HELL /E DITOR
Open IDLE (Integrated Development and Learning Environment). IDLE shell opens
and one can start working
Select “New File” from “File” menu.
The Editor will open. We type Python program here and then use the interpreter to
execute the content from the file.
Files to be saved with extension .py
PYTHON - An Introduction 23 / 63
Keywords and Identifiers
Keywords are the reserved words in Python used by Python interpreter to recognize
the structure of the program.
PYTHON - An Introduction 24 / 63
Keywords and Identifiers
Keywords are the reserved words in Python used by Python interpreter to recognize
the structure of the program.
Identifiers are the name given to entities like class, functions, variables etc. It helps
to differentiate one entity from another.
PYTHON - An Introduction 24 / 63
Keywords and Identifiers
Keywords are the reserved words in Python used by Python interpreter to recognize
the structure of the program.
Identifiers are the name given to entities like class, functions, variables etc. It helps
to differentiate one entity from another.
Identifiers can be a combination of letters from “a” to “z”, from “A” to “Z” and digits from
“0” to “9” or special character _,.
PYTHON - An Introduction 24 / 63
Keywords and Identifiers
Keywords are the reserved words in Python used by Python interpreter to recognize
the structure of the program.
Identifiers are the name given to entities like class, functions, variables etc. It helps
to differentiate one entity from another.
Identifiers can be a combination of letters from “a” to “z”, from “A” to “Z” and digits from
“0” to “9” or special character _,.
Keywords cannot be used as identifiers.
PYTHON - An Introduction 24 / 63
Keywords and Identifiers
Keywords are the reserved words in Python used by Python interpreter to recognize
the structure of the program.
Identifiers are the name given to entities like class, functions, variables etc. It helps
to differentiate one entity from another.
Identifiers can be a combination of letters from “a” to “z”, from “A” to “Z” and digits from
“0” to “9” or special character _,.
Keywords cannot be used as identifiers.
Only special character used in identifiers is _.
PYTHON - An Introduction 24 / 63
Keywords and Identifiers
Keywords are the reserved words in Python used by Python interpreter to recognize
the structure of the program.
Identifiers are the name given to entities like class, functions, variables etc. It helps
to differentiate one entity from another.
Identifiers can be a combination of letters from “a” to “z”, from “A” to “Z” and digits from
“0” to “9” or special character _,.
Keywords cannot be used as identifiers.
Only special character used in identifiers is _.
Identifier can be of any length.
PYTHON - An Introduction 24 / 63
Keywords and Identifiers
for while in is
PYTHON - An Introduction 25 / 63
Keywords and Identifiers
DATA TYPES
Variables can store data of different types, and different types can do different things.
PYTHON - An Introduction 26 / 63
Keywords and Identifiers
DATA TYPES
Variables can store data of different types, and different types can do different things.
Python has the following data types built-in by default, in these categories:
PYTHON - An Introduction 26 / 63
Keywords and Identifiers
DATA TYPES
Variables can store data of different types, and different types can do different things.
Python has the following data types built-in by default, in these categories:
PYTHON - An Introduction 26 / 63
Keywords and Identifiers
E XAMPLES :
a =2.4
x=3
y= ’a ’
z =" H e l l o "
p r i n t ( type ( a ) ) # t y p e ( ) g i v e s t h e data t y p e o f t h e v a r i a b l e .
p r i n t ( type ( x ) )
p r i n t ( type ( y ) )
p r i n t ( type ( z ) )
PYTHON - An Introduction 27 / 63
Keywords and Identifiers
x = 1 # int
y = 2.8 # f l o a t
z = 1j # complex
X = 35e3 # e i n d i c a t e s t h e power o f 10
Y = 12E4
Z = −87.7 e100
PYTHON - An Introduction 28 / 63
Keywords and Identifiers
Strings in python are surrounded by either single quotation marks, or double quotation
marks.
PYTHON - An Introduction 29 / 63
Keywords and Identifiers
Strings in python are surrounded by either single quotation marks, or double quotation
marks.
a = " Hello "
print (a)
PYTHON - An Introduction 29 / 63
Operators
O PERATORS
PYTHON - An Introduction 30 / 63
Operators
A RITHMETIC O PERATORS
All the common algebraic operators presented in the following table are available in Python.
Addition +
Subtraction −
Multiplication ∗
Division /
Integer Division //
Power **
Remainder %
PYTHON - An Introduction 31 / 63
Operators
C OMPARISON O PERATORS
Comparison operators:
< less than
> greater than
<= less than or equal to
>= greater than or equal to
== equal to
!= not equal to
PYTHON - An Introduction 32 / 63
Operators
L OGICAL OPERATORS
Logical operators:
PYTHON - An Introduction 33 / 63
Operators
A SSIGNMENT O PERATOR
PYTHON - An Introduction 34 / 63
Operators
I DENTITY O PERATORS
Identity Operators
is Returns True if both variables are
the same object
is not Returns True if both variables are
not the same object
PYTHON - An Introduction 35 / 63
Operators
M EMBERSHIP O PERATORS
Membership Operators
in Returns True if a sequence with the
specified value is present in the ob-
ject
not in Returns True if a sequence with the
specified value is not present in the
object
PYTHON - An Introduction 36 / 63
Operators
E XERCISE :
PYTHON - An Introduction 37 / 63
Operators
E XERCISE :
PYTHON - An Introduction 38 / 63
Operators
E XERCISE :
PYTHON - An Introduction 39 / 63
Operators
E XERCISE :
PYTHON - An Introduction 40 / 63
Lists, Tuples, Sets
Lists
Tuples
Sets
These are used to store collections of data.
PYTHON - An Introduction 41 / 63
Lists, Tuples, Sets
L ISTS , T UPLES
PYTHON - An Introduction 42 / 63
Lists, Tuples, Sets
L ISTS , T UPLES
PYTHON - An Introduction 42 / 63
Lists, Tuples, Sets
L ISTS , T UPLES
PYTHON - An Introduction 42 / 63
Lists, Tuples, Sets
L ISTS , T UPLES
PYTHON - An Introduction 42 / 63
Lists, Tuples, Sets
L ISTS , T UPLES
PYTHON - An Introduction 42 / 63
Lists, Tuples, Sets
L ISTS , T UPLES
PYTHON - An Introduction 42 / 63
Lists, Tuples, Sets
ordered, it means that the items have a defined order, and that order will not change.
PYTHON - An Introduction 43 / 63
Lists, Tuples, Sets
ordered, it means that the items have a defined order, and that order will not change.
If you add new items to a list, the new items will be placed at the end of the list.
PYTHON - An Introduction 43 / 63
Lists, Tuples, Sets
ordered, it means that the items have a defined order, and that order will not change.
If you add new items to a list, the new items will be placed at the end of the list.
The list is changeable, meaning that we can change, add, and remove items in a list
after it has been created.
PYTHON - An Introduction 43 / 63
Lists, Tuples, Sets
ordered, it means that the items have a defined order, and that order will not change.
If you add new items to a list, the new items will be placed at the end of the list.
The list is changeable, meaning that we can change, add, and remove items in a list
after it has been created.
Since lists/tuples are indexed, lists can have items with the same value.
PYTHON - An Introduction 43 / 63
Lists, Tuples, Sets
ordered, it means that the items have a defined order, and that order will not change.
If you add new items to a list, the new items will be placed at the end of the list.
The list is changeable, meaning that we can change, add, and remove items in a list
after it has been created.
Since lists/tuples are indexed, lists can have items with the same value.
List/tuple items can be of any data type.
PYTHON - An Introduction 43 / 63
Lists, Tuples, Sets
ordered, it means that the items have a defined order, and that order will not change.
If you add new items to a list, the new items will be placed at the end of the list.
The list is changeable, meaning that we can change, add, and remove items in a list
after it has been created.
Since lists/tuples are indexed, lists can have items with the same value.
List/tuple items can be of any data type.
A list/tuple can contain different data types
PYTHON - An Introduction 43 / 63
Lists, Tuples, Sets
PYTHON - An Introduction 44 / 63
Lists, Tuples, Sets
PYTHON - An Introduction 44 / 63
Lists, Tuples, Sets
PYTHON - An Introduction 44 / 63
Lists, Tuples, Sets
PYTHON - An Introduction 44 / 63
Lists, Tuples, Sets
PYTHON - An Introduction 45 / 63
Lists, Tuples, Sets
PYTHON - An Introduction 45 / 63
Lists, Tuples, Sets
PYTHON - An Introduction 45 / 63
Lists, Tuples, Sets
PYTHON - An Introduction 45 / 63
Lists, Tuples, Sets
PYTHON - An Introduction 45 / 63
Lists, Tuples, Sets
PYTHON - An Introduction 45 / 63
Lists, Tuples, Sets
PYTHON - An Introduction 45 / 63
Lists, Tuples, Sets
PYTHON - An Introduction 45 / 63
Lists, Tuples, Sets
S ETS
PYTHON - An Introduction 46 / 63
Lists, Tuples, Sets
S ETS
PYTHON - An Introduction 46 / 63
Lists, Tuples, Sets
S ETS
PYTHON - An Introduction 46 / 63
Lists, Tuples, Sets
S ETS
PYTHON - An Introduction 46 / 63
Lists, Tuples, Sets
S ETS
PYTHON - An Introduction 46 / 63
Lists, Tuples, Sets
S ETS
PYTHON - An Introduction 46 / 63
Lists, Tuples, Sets
S ETS
PYTHON - An Introduction 46 / 63
Lists, Tuples, Sets
E XERCISE :
PYTHON - An Introduction 47 / 63
Lists, Tuples, Sets
E XERCISE :
PYTHON - An Introduction 48 / 63
Lists, Tuples, Sets
E XERCISE :
PYTHON - An Introduction 49 / 63
Lists, Tuples, Sets
E XERCISE :
PYTHON - An Introduction 50 / 63
Lists, Tuples, Sets
E XERCISE :
PYTHON - An Introduction 51 / 63
Lists, Tuples, Sets
E XERCISE :
PYTHON - An Introduction 52 / 63
Input and output statements
I NPUT STATEMENT
For example:
x = i n p u t ( ’ E n t e r your name : ’ )
p r i n t ( ’ H e l l o , ’ +x )
p r i n t ( ’ Hello , ’ , x )
p r i n t ( type ( x ) )
PYTHON - An Introduction 53 / 63
Input and output statements
I NPUT STATEMENT
PYTHON - An Introduction 54 / 63
Input and output statements
I NPUT STATEMENT
PYTHON - An Introduction 54 / 63
Input and output statements
O UTPUT STATEMENTS
Python provides the print() function to display output to the standard output devices.
S YNTAX :
print(value(s),sep= ’ ’, end = ‘\n’, file=file, flush=flush)
value(s) – Any value, and as many as you like. Will be converted to string before printed
sep=‘separator’ – (Optional) Specify how to separate the objects, if there is more than
one. Default :’ ’
end=‘end’ – (Optional) Specify what to print at the end.Default : ‘\n’
file – (Optional) An object with a write method. Default :sys.stdout
flush – (Optional) A Boolean, specifying if the output is flushed (True) or buffered (False).
Default: False
PYTHON - An Introduction 55 / 63
Input and output statements
PYTHON - An Introduction 56 / 63
Input and output statements
F ORMATTING OUTPUT
C ODE 1:
name = "REVA"
p r i n t ( f ’ Welcome t o { name } ! ’ )
PYTHON - An Introduction 57 / 63
Input and output statements
C ODE 2:
a = 20
b = 10
# addition
sum = a + b
# subtraction
sub = a− b
# Output
p r i n t ( ’ The v a l u e o f a i s { } and b i s { } ’ . f o r m a t ( a , b ) )
p r i n t ( ’ { 2 } i s t h e sum o f { 0 } and { 1 } ’ . f o r m a t ( a , b , sum ) )
p r i n t ( ’ { sub_value } i s t h e s u b t r a c t i o n o f { value_a } and { value_b } ’
. f o r m a t ( value_a = a , value_b = b , sub_value =sub ) )
PYTHON - An Introduction 58 / 63
Input and output statements
U SING % O PERATOR
We can use ‘%’ operator. % values are replaced with zero or more value of elements. The
formatting using % is similar to that of ‘printf’ in the C programming language.
%d – integer
%f – float
%s – string
%x – hexadecimal
%o – octal
PYTHON - An Introduction 59 / 63
Input and output statements
E XAMPLE
C ODE
PYTHON - An Introduction 60 / 63
Input and output statements
E XAMPLE
C ODE
C ODE :
x = 12.3456789
p r i n t ( ’ The v a l u e o f x i s %3.2 f ’ %x )
p r i n t ( ’ The v a l u e o f x i s %3.4 f ’ %x )
PYTHON - An Introduction 60 / 63
Input and output statements
O UTPUT STATEMENTS
display() command can be used to get the output printed on the screen. For example
x = 12.3456789
d i s p l a y ( ’ The v a l u e o f x i s %3.2 f ’ %x )
d i s p l a y ( ’ The v a l u e o f x i s ’ , x )
PYTHON - An Introduction 61 / 63
Input and output statements
O UTPUT STATEMENTS
display() command can be used to get the output printed on the screen. For example
x = 12.3456789
d i s p l a y ( ’ The v a l u e o f x i s %3.2 f ’ %x )
d i s p l a y ( ’ The v a l u e o f x i s ’ , x )
PYTHON - An Introduction 61 / 63
Input and output statements
E XERCISES :
PYTHON - An Introduction 62 / 63
Input and output statements
Thank You
PYTHON - An Introduction 63 / 63