SlideShare a Scribd company logo
1
Chapter 5
PYTHON VARIABLES AND
OPERATORS
Appreciate the use of Graphical User
Interface (GUI) and Integrated
Development Environment (IDE) for
creating Python programs.
•Work in Interactive & Script mode for
programming.
•Create and assign values to variables.
•Understand the concept and usage of
different data types in Python.
•Appreciate the importance and usage of
different types of operators (Arithmetic,
2
• Python is a general purpose
programming language
• Created by Guido Van Rossum from
CWI (Centrum Wiskunde &
Informatica) which is a National
Research Institute for Mathematics
and Computer Science in Netherlands.
3
• The language was released in I991.
• Python got its name from a BBC comedy
series from seventies- “Monty Python’s
Flying Circus”.
• Python supports both Procedural and
Object Oriented programming
approaches. 4
Key features of
Python
5
• It is a general purpose programming
language which can be used for both
scientific and non-scientific programming
• It is a platform independent
programming language.
• The programs written in Python are
easily readable and understandable.
6
Programming in
Python
7
In Python, programs can be written in two ways
namely
• Interactive mode
• Script mode
The Interactive mode allows us to write codes in
Python command prompt (>>>)
In script mode programs can be written and stored as
separate file with the extension .py and executed.
Script mode is used to create and edit python source
file. 8
Interactive mode
Programming
In interactive mode Python
code can be directly typed and
the interpreter displays the
result(s) immediately. 9
Invoking
Python IDLE
10
11
The prompt (>>>) indicates
that Interpreter is ready to
acceptctions. Therefore, the
prompt on screen means
IDLE is working in interactive
mode. 12
>>> 5/2
2.5
>>> 2/5
0.4
>>> 4%2
0
>>> 5%2
1
>>> 5//2
2
>>> 5+40
45
>>> 5**2
25
>>> 5+5*2
15
>>> a=3
>>> a+=4
>>> print(a)
7 13
Script mode Programming
A script is a text file containing the Python
statements.
Python Scripts are reusable code.
Once the script is created, it can be
executed again and again without
retyping. 14
Input and
Output
Functions 15
A program needs to interact with the user
to accomplish the desired task; this can be
achieved using Input-Output functions.
The input() function helps to enter data
at run time by the user.
The output function print() is used to
display the result of the program on the
screen after execution. 16
The print() function
In Python, the print()
function is used to
display result on the
screen. 17
syntax
• print (“string to be displayed as output ” )
• print (variable )
• print (“String to be displayed as output ”,
variable)
• print (“String1 ”, variable, “String 2”,
variable, “String 3” ……)
18
19
The print () evaluates the expression
before printing it on the monitor.
The print () displays an entire
statement which is specified within
print ( ).
Comma ( , ) is used as a separator in
print ( ) to print more than one item.
20
>>> x=5
>>> y=5
>>> z=x+y
>>> print("The sum of ", x," and" , y," is “ ,z)
The sum of 5 and 5 is 10
example
21
input( ) function
In Python, input( ) function is used
to accept data as input at run time.
The syntax for input() function is,
Variable = input (“prompt
string”) 22
>>> name=input("enter your name:")
enter your name: sunesh
>>> print("i'm ",name)
i'm sunesh
>>> city=input()
hello
>>> print("im from:",city)
im from: hello 23
x,y=int (input("Enter Number 1:")),
int(input("Enter Number 2:"))
Enter Number 1 : 40
Enter Number 2: 30
>>> c=x+y
>>> print(c)
70
24
Comments
in Python25
In Python, comments begin with hash symbol
(#).
The lines that begins with # are considered as
comments and ignored by the Python
interpreter. Comments may be
• Single line
• Multi-lines.
The multiline comments should be enclosed
within a set of # as given below. 26
# It is Single line Comment
# It is multiline comment
which contains more than one line #
Example
27
Tokens
28
Python breaks each logical
line into a sequence of
elementary lexical
components known as
Tokens. 29
1) Identifiers
2) Keywords
3) Operators
4) Delimiters
5) Literals 30
Identifiers
31
An Identifier is a name
used to identify a
variable, function, class,
module or object.
32
• An identifier must start with an alphabet
(A..Z or a..z) or underscore ( _ ).
• Identifiers may contain digits (0 .. 9)
• Python identifiers are case sensitive i.e.
uppercase and lowercase letters are distinct.
• Identifiers must not be a python keyword.
• Python does not allow punctuation character
such as %,$, @ etc., within identifiers.
33
Example of valid identifiers
Sum, total_marks, regno, num1
Example of invalid identifiers
12Name, name$, total-mark,
continue
34
Keywords
35
Keywords are special words used
by Python interpreter to recognize
the structure of program. As these
words have specific meaning for
interpreter, they cannot be used
for any other purpose.
36
37
Operators
38
In computer programming
languages operators are
special symbols which
represent computations,
conditional matching etc.
39
The value of an operator used is
called operands.
Operators are categorized as
Arithmetic, Relational, Logical,
Assignment etc. Value and
variables when used with operator
are known as operands. 40
Arithmetic
operators41
An arithmetic operator is
a mathematical operator
that takes two operands
and performs a
calculation on them.
42
Most computer languages
contain a set of such operators
that can be used within
equations to perform different
types of sequential
calculations. 43
>>> a=100
>>> b=10
>>> print ("The Sum = ",a+b)
The Sum = 110
>>> print ("The Difference = ",a-b)
The Difference = 90
>>> print ("The Product = ",a*b)
The Product = 1000
>>> print ("The Quotient = ",a/b)
The Quotient = 10.0
>>> print ("The Remainder = ",a%30)
The Remainder = 10 44
Relational or
Comparative
operators 45
A Relational operator is also called
as Comparative operator which
checks the relationship between
two operands.
If the relation is true, it returns
True; otherwise it returns False.
46
47
>>> a=10
>>> b=20
>>> a==b
False
>>> a<b
True
>>> a>b
False
>>> a<=b
True
>>> a>=b
False
>>> a!=b
True 48
Logical
operators
49
In python, Logical operators
are used to perform logical
operations on the given
relational expressions. There
are three logical operators they
are and, or and not. 50
Assignment
operators
51
In Python, = is a simple assignment operator to
assign values to variable.
Let a = 5 and b = 10 assigns the value 5 to a and
10 to b these two assignment statement can
also be given as a,b=5,10 that assigns the value
5 and 10 on the right to the variables a and b
respectively. There are various compound
operators in Python like +=, -=, *=, /=, %=, **=
and //= are also available. 52
x=int (input("Type a Value for X : "))
print ("X = ",x)
x+=2
print ("X = ",x)
x-=2
print ("X = ",x)
x*=2
print ("X = ",x)
x/=2
print ("X = ",x)
x%=2
print ("X = ",x)
x**=2
print ("X = ",x)
x//=2
print ("X = ",x)
Type a Value for X : 10
X = 10
X = 12
X = 10
X = 20
X = 10.0
X = 0.0
X = 0.0
X = 0.0
53
Conditional
operator
54
Ternary operator is also known as
conditional operator that evaluate
something based on a condition
being true or false.
It simply allows testing a condition
in a single line replacing the multi-
line if-else making the code compact.
syntax
Variable Name = [on_true]
if [Test expression] else
[on_false]
56
a=10
b=20
min = a if a < b else b
print("The Minimum value is....",
min)
Example
57
Delimiters
58
Python uses the symbols and symbol
combinations as delimiters in expressions,
lists, dictionaries and strings. Following
are the delimiters.
59
Literals
60
Literal is a raw data given in
a variable or constant. In
Python, there are various
types of literals.
61
Numeric
Literals 62
Numeric Literals consists of
digits and are immutable
(unchangeable).
Numeric literals can belong to
3 different numerical types
Integer, Float and Complex. 63
String
Literals64
In Python a string literal is a sequence of
characters surrounded by quotes.
Python supports single, double and triple
quotes for a string.
A character literal is a single character
surrounded by single or double quotes.
The value with triple-quote "' '" is used to
give multi-line string literal. 65
Boolean
Literals66
A Boolean literal can
have any of the two
values: True or False.
67
boolean_1 = True
boolean_2 = False
print ("Demo Program for Boolean Literals")
print ("Boolean Value1 :",boolean_1)
print ("Boolean Value2 :",boolean_2)
Demo Program for Boolean Literals
('Boolean Value1 :', True)
('Boolean Value2 :', False)
68
Escape
Sequences
69
In Python strings, the backslash ""
is a special character, also called
the "escape" character.
It is used in representing certain
whitespace characters: "t" is a
tab, "n" is a newline, and "r" is a
carriage return. 70
Python
Data types
71
All data values in Python are
objects and each object or value
has type. Python has Built-in or
Fundamental data types such as
Number, String, Boolean, tuples,
lists and dictionaries.
72
Number
Data type
73
The built-in number objects in Python supports
integers, floating point numbers and complex
numbers.
Integer Data can be decimal, octal or
hexadecimal.
Octal integer use O (both upper and lower
case) to denote octal digits and hexadecimal
integer use OX (both upper and lower case)
and L (only upper case) to denote long integer.
74
example
# Decimal integers
102, 4567, 567
# Octal integers
O102, o876, O432
# Hexadecimal integers
OX102, oX876, OX432
# Long decimal integers
34L, 523L 75
A floating point data is represented
by a sequence of decimal digits
that includes a decimal point.
An Exponent data contains decimal
digit part, decimal point, exponent
part followed by one or more
digits. 76
example
# Floating point data
123.34, 456.23, 156.23
# Exponent data
12.E04, 24.e04 77
Complex number is made
up of two floating point
values, one each for the
real and imaginary parts.
78
Boolean
Data type
79
A Boolean data can
have any of the
two values: True or
False. 80
example
Bool_var1=True
Bool_var2=False
81
String
Data type82
String data can be
enclosed with single
quote or double quote
or triple quote.
83
84
Thank you
Tamil
85

More Related Content

Similar to chapter_5_ppt_em_220247.pptx

Python basics
Python basicsPython basics
Python basics
Manisha Gholve
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
Mohd Sajjad
 
BASICS OF PYTHON usefull for the student who would like to learn on their own
BASICS OF PYTHON usefull for the student who would like to learn on their ownBASICS OF PYTHON usefull for the student who would like to learn on their own
BASICS OF PYTHON usefull for the student who would like to learn on their own
Nandini485510
 
Python Basics by Akanksha Bali
Python Basics by Akanksha BaliPython Basics by Akanksha Bali
Python Basics by Akanksha Bali
Akanksha Bali
 
Python
PythonPython
Python
Aashish Jain
 
Python For Machine Learning
Python For Machine LearningPython For Machine Learning
Python For Machine Learning
YounesCharfaoui
 
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdfpython-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
KosmikTech1
 
Python introduction towards data science
Python introduction towards data sciencePython introduction towards data science
Python introduction towards data science
deepak teja
 
Python Scipy Numpy
Python Scipy NumpyPython Scipy Numpy
Python Scipy Numpy
Girish Khanzode
 
Welcome to python workshop
Welcome to python workshopWelcome to python workshop
Welcome to python workshop
Mukul Kirti Verma
 
17575602.ppt
17575602.ppt17575602.ppt
17575602.ppt
TejaValmiki
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
Anonymous9etQKwW
 
Python fundamentals
Python fundamentalsPython fundamentals
Python fundamentals
natnaelmamuye
 
Introduction to phyton , important topic
Introduction to phyton , important topicIntroduction to phyton , important topic
Introduction to phyton , important topic
akpgenious67
 
Python by Rj
Python by RjPython by Rj
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
RojaPriya
 
Introduction of Python
Introduction of PythonIntroduction of Python
Introduction of Python
ZENUS INFOTECH INDIA PVT. LTD.
 
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
PART - 1  Python Introduction- Variables- Data types - Numeric- String- Boole...PART - 1  Python Introduction- Variables- Data types - Numeric- String- Boole...
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
manikamr074
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
kavinilavuG
 
gdscpython.pdf
gdscpython.pdfgdscpython.pdf
gdscpython.pdf
workvishalkumarmahat
 

Similar to chapter_5_ppt_em_220247.pptx (20)

Python basics
Python basicsPython basics
Python basics
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
 
BASICS OF PYTHON usefull for the student who would like to learn on their own
BASICS OF PYTHON usefull for the student who would like to learn on their ownBASICS OF PYTHON usefull for the student who would like to learn on their own
BASICS OF PYTHON usefull for the student who would like to learn on their own
 
Python Basics by Akanksha Bali
Python Basics by Akanksha BaliPython Basics by Akanksha Bali
Python Basics by Akanksha Bali
 
Python
PythonPython
Python
 
Python For Machine Learning
Python For Machine LearningPython For Machine Learning
Python For Machine Learning
 
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdfpython-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
 
Python introduction towards data science
Python introduction towards data sciencePython introduction towards data science
Python introduction towards data science
 
Python Scipy Numpy
Python Scipy NumpyPython Scipy Numpy
Python Scipy Numpy
 
Welcome to python workshop
Welcome to python workshopWelcome to python workshop
Welcome to python workshop
 
17575602.ppt
17575602.ppt17575602.ppt
17575602.ppt
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
 
Python fundamentals
Python fundamentalsPython fundamentals
Python fundamentals
 
Introduction to phyton , important topic
Introduction to phyton , important topicIntroduction to phyton , important topic
Introduction to phyton , important topic
 
Python by Rj
Python by RjPython by Rj
Python by Rj
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
 
Introduction of Python
Introduction of PythonIntroduction of Python
Introduction of Python
 
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
PART - 1  Python Introduction- Variables- Data types - Numeric- String- Boole...PART - 1  Python Introduction- Variables- Data types - Numeric- String- Boole...
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
 
gdscpython.pdf
gdscpython.pdfgdscpython.pdf
gdscpython.pdf
 

Recently uploaded

Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
aqil azizi
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 

Recently uploaded (20)

Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 

chapter_5_ppt_em_220247.pptx

  • 2. Appreciate the use of Graphical User Interface (GUI) and Integrated Development Environment (IDE) for creating Python programs. •Work in Interactive & Script mode for programming. •Create and assign values to variables. •Understand the concept and usage of different data types in Python. •Appreciate the importance and usage of different types of operators (Arithmetic, 2
  • 3. • Python is a general purpose programming language • Created by Guido Van Rossum from CWI (Centrum Wiskunde & Informatica) which is a National Research Institute for Mathematics and Computer Science in Netherlands. 3
  • 4. • The language was released in I991. • Python got its name from a BBC comedy series from seventies- “Monty Python’s Flying Circus”. • Python supports both Procedural and Object Oriented programming approaches. 4
  • 6. • It is a general purpose programming language which can be used for both scientific and non-scientific programming • It is a platform independent programming language. • The programs written in Python are easily readable and understandable. 6
  • 8. In Python, programs can be written in two ways namely • Interactive mode • Script mode The Interactive mode allows us to write codes in Python command prompt (>>>) In script mode programs can be written and stored as separate file with the extension .py and executed. Script mode is used to create and edit python source file. 8
  • 9. Interactive mode Programming In interactive mode Python code can be directly typed and the interpreter displays the result(s) immediately. 9
  • 11. 11
  • 12. The prompt (>>>) indicates that Interpreter is ready to acceptctions. Therefore, the prompt on screen means IDLE is working in interactive mode. 12
  • 13. >>> 5/2 2.5 >>> 2/5 0.4 >>> 4%2 0 >>> 5%2 1 >>> 5//2 2 >>> 5+40 45 >>> 5**2 25 >>> 5+5*2 15 >>> a=3 >>> a+=4 >>> print(a) 7 13
  • 14. Script mode Programming A script is a text file containing the Python statements. Python Scripts are reusable code. Once the script is created, it can be executed again and again without retyping. 14
  • 16. A program needs to interact with the user to accomplish the desired task; this can be achieved using Input-Output functions. The input() function helps to enter data at run time by the user. The output function print() is used to display the result of the program on the screen after execution. 16
  • 17. The print() function In Python, the print() function is used to display result on the screen. 17
  • 18. syntax • print (“string to be displayed as output ” ) • print (variable ) • print (“String to be displayed as output ”, variable) • print (“String1 ”, variable, “String 2”, variable, “String 3” ……) 18
  • 19. 19
  • 20. The print () evaluates the expression before printing it on the monitor. The print () displays an entire statement which is specified within print ( ). Comma ( , ) is used as a separator in print ( ) to print more than one item. 20
  • 21. >>> x=5 >>> y=5 >>> z=x+y >>> print("The sum of ", x," and" , y," is “ ,z) The sum of 5 and 5 is 10 example 21
  • 22. input( ) function In Python, input( ) function is used to accept data as input at run time. The syntax for input() function is, Variable = input (“prompt string”) 22
  • 23. >>> name=input("enter your name:") enter your name: sunesh >>> print("i'm ",name) i'm sunesh >>> city=input() hello >>> print("im from:",city) im from: hello 23
  • 24. x,y=int (input("Enter Number 1:")), int(input("Enter Number 2:")) Enter Number 1 : 40 Enter Number 2: 30 >>> c=x+y >>> print(c) 70 24
  • 26. In Python, comments begin with hash symbol (#). The lines that begins with # are considered as comments and ignored by the Python interpreter. Comments may be • Single line • Multi-lines. The multiline comments should be enclosed within a set of # as given below. 26
  • 27. # It is Single line Comment # It is multiline comment which contains more than one line # Example 27
  • 29. Python breaks each logical line into a sequence of elementary lexical components known as Tokens. 29
  • 30. 1) Identifiers 2) Keywords 3) Operators 4) Delimiters 5) Literals 30
  • 32. An Identifier is a name used to identify a variable, function, class, module or object. 32
  • 33. • An identifier must start with an alphabet (A..Z or a..z) or underscore ( _ ). • Identifiers may contain digits (0 .. 9) • Python identifiers are case sensitive i.e. uppercase and lowercase letters are distinct. • Identifiers must not be a python keyword. • Python does not allow punctuation character such as %,$, @ etc., within identifiers. 33
  • 34. Example of valid identifiers Sum, total_marks, regno, num1 Example of invalid identifiers 12Name, name$, total-mark, continue 34
  • 36. Keywords are special words used by Python interpreter to recognize the structure of program. As these words have specific meaning for interpreter, they cannot be used for any other purpose. 36
  • 37. 37
  • 39. In computer programming languages operators are special symbols which represent computations, conditional matching etc. 39
  • 40. The value of an operator used is called operands. Operators are categorized as Arithmetic, Relational, Logical, Assignment etc. Value and variables when used with operator are known as operands. 40
  • 42. An arithmetic operator is a mathematical operator that takes two operands and performs a calculation on them. 42
  • 43. Most computer languages contain a set of such operators that can be used within equations to perform different types of sequential calculations. 43
  • 44. >>> a=100 >>> b=10 >>> print ("The Sum = ",a+b) The Sum = 110 >>> print ("The Difference = ",a-b) The Difference = 90 >>> print ("The Product = ",a*b) The Product = 1000 >>> print ("The Quotient = ",a/b) The Quotient = 10.0 >>> print ("The Remainder = ",a%30) The Remainder = 10 44
  • 46. A Relational operator is also called as Comparative operator which checks the relationship between two operands. If the relation is true, it returns True; otherwise it returns False. 46
  • 47. 47
  • 48. >>> a=10 >>> b=20 >>> a==b False >>> a<b True >>> a>b False >>> a<=b True >>> a>=b False >>> a!=b True 48
  • 50. In python, Logical operators are used to perform logical operations on the given relational expressions. There are three logical operators they are and, or and not. 50
  • 52. In Python, = is a simple assignment operator to assign values to variable. Let a = 5 and b = 10 assigns the value 5 to a and 10 to b these two assignment statement can also be given as a,b=5,10 that assigns the value 5 and 10 on the right to the variables a and b respectively. There are various compound operators in Python like +=, -=, *=, /=, %=, **= and //= are also available. 52
  • 53. x=int (input("Type a Value for X : ")) print ("X = ",x) x+=2 print ("X = ",x) x-=2 print ("X = ",x) x*=2 print ("X = ",x) x/=2 print ("X = ",x) x%=2 print ("X = ",x) x**=2 print ("X = ",x) x//=2 print ("X = ",x) Type a Value for X : 10 X = 10 X = 12 X = 10 X = 20 X = 10.0 X = 0.0 X = 0.0 X = 0.0 53
  • 55. Ternary operator is also known as conditional operator that evaluate something based on a condition being true or false. It simply allows testing a condition in a single line replacing the multi- line if-else making the code compact.
  • 56. syntax Variable Name = [on_true] if [Test expression] else [on_false] 56
  • 57. a=10 b=20 min = a if a < b else b print("The Minimum value is....", min) Example 57
  • 59. Python uses the symbols and symbol combinations as delimiters in expressions, lists, dictionaries and strings. Following are the delimiters. 59
  • 61. Literal is a raw data given in a variable or constant. In Python, there are various types of literals. 61
  • 63. Numeric Literals consists of digits and are immutable (unchangeable). Numeric literals can belong to 3 different numerical types Integer, Float and Complex. 63
  • 65. In Python a string literal is a sequence of characters surrounded by quotes. Python supports single, double and triple quotes for a string. A character literal is a single character surrounded by single or double quotes. The value with triple-quote "' '" is used to give multi-line string literal. 65
  • 67. A Boolean literal can have any of the two values: True or False. 67
  • 68. boolean_1 = True boolean_2 = False print ("Demo Program for Boolean Literals") print ("Boolean Value1 :",boolean_1) print ("Boolean Value2 :",boolean_2) Demo Program for Boolean Literals ('Boolean Value1 :', True) ('Boolean Value2 :', False) 68
  • 70. In Python strings, the backslash "" is a special character, also called the "escape" character. It is used in representing certain whitespace characters: "t" is a tab, "n" is a newline, and "r" is a carriage return. 70
  • 72. All data values in Python are objects and each object or value has type. Python has Built-in or Fundamental data types such as Number, String, Boolean, tuples, lists and dictionaries. 72
  • 74. The built-in number objects in Python supports integers, floating point numbers and complex numbers. Integer Data can be decimal, octal or hexadecimal. Octal integer use O (both upper and lower case) to denote octal digits and hexadecimal integer use OX (both upper and lower case) and L (only upper case) to denote long integer. 74
  • 75. example # Decimal integers 102, 4567, 567 # Octal integers O102, o876, O432 # Hexadecimal integers OX102, oX876, OX432 # Long decimal integers 34L, 523L 75
  • 76. A floating point data is represented by a sequence of decimal digits that includes a decimal point. An Exponent data contains decimal digit part, decimal point, exponent part followed by one or more digits. 76
  • 77. example # Floating point data 123.34, 456.23, 156.23 # Exponent data 12.E04, 24.e04 77
  • 78. Complex number is made up of two floating point values, one each for the real and imaginary parts. 78
  • 80. A Boolean data can have any of the two values: True or False. 80
  • 83. String data can be enclosed with single quote or double quote or triple quote. 83
  • 84. 84