SlideShare a Scribd company logo
http://www.skillbrew.com
/SkillbrewTalent brewed by the industry itself
Operators
Pavan Verma
@YinYangPavan
Python Programming Essentials
1
© SkillBrew http://skillbrew.com
Comparison operators
2
>>> 200 > 199
True
>>> 'foo' > 'bar'
True
>>> 100 < 90
False
>>> 'Foobar' <= 'Foobar'
True
Operator Description
a > b Greater than
a < b Less than
a >= b Greater than or equal
to
a <= b Less than or equal to
a == b Check if value of two
operands is equal
a != b Check if value of two
operands is not equal
© SkillBrew http://skillbrew.com
Comparison operators (2)
3
>>> 101 >= 100.0
True
>>> 100.01 == 100.01
True
>>> 'game' != 'game'
False
Operator Description
a > b Greater than
a < b Less than
a >= b Greater than or equal
to
a <= b Less than or equal to
a == b Check if value of two
operands is equal
a != b Check if value of two
operands is not equal
© SkillBrew http://skillbrew.com
Logical operators
4
>>> a, b, c = 10, 20, 30
>>> (a > b) and (b < c)
False
>>> (a < b) and (b < c)
True
>>> (a > b) or (b < c)
True
Operator Description
a and b Logical AND
If both operands are
True than it returns
True
a or b Logical OR
If one of the operands
is True then it returns
True
not Logical NOT
© SkillBrew http://skillbrew.com
Logical operators
5
>>> a, b, c = 10, 20, 30
>>> not a
False
>>> not (a > b)
True
>>> a > b
False
Operator Description
a and b Logical AND
If both operands are
True than it returns
True
a or b Logical OR
If one of the operands
is True then it returns
True
not Logical NOT
© SkillBrew http://skillbrew.com
Shorthand operators
6
>>> x = 5
>>> x +=1 # x = x + 1
>>> x
6
>>> x -=2 # x = x - 2
>>> x
4
>>> x *=3 # x = x * 3
>>> x
12
© SkillBrew http://skillbrew.com
Shorthand operators (2)
7
>>> x /=4
>>> x
3
>>> x >>=1
>>> x
1
>>> x <<=2
>>> x
4
>>> x **=3
>>> x
64
© SkillBrew http://skillbrew.com
Increment and decrement
the ++ and -- operators were left out for consistency and
simplicity
>>> x = 5
>>> x += 1
>>> x
6
>>> x -= 2
>>> x
4
8
Use shorthand
operators to
perform increment
and decrement
9
Operator Precedence
© SkillBrew http://skillbrew.com
Why is operator precedence required?
10
This one Python statement
could mean many things
hence we need operator
precedence to determine
the order in which evaluation
takes place
>>> 10 + 20 * 30 / 10
70
>>> (10 + 20) * 30 / 10
90
>>> 10 + (20 * 30) / 10
70
>>> (10 + 20 * 30) / 10
61
>>> 10 + 20 * (30 / 10)
70
© SkillBrew http://skillbrew.com
Operator precedence (highest to lowest)
Operator Description
** exponentiation (raise to the power)
~ Complement
*, /, %, // multiply, divide, modulo and floor
division
+, - addition and subtraction
>>, << right and left bitwise shift
& bitwise 'AND'
11
© SkillBrew http://skillbrew.com
Operator precedence (highest to lowest) (2)
Operator Description
^, | Bitwise exclusive `OR' and regular
`OR'
<=, >= Comparison operators
==, != Equality operators
%=, /=, -=, +=, *=, **= Shorthand operators
is, is not Identity operators
in, not in Membership operators
not , or, and Logical operators
12
© SkillBrew http://skillbrew.com
Operator precedence (3)
13
>>> 10 + 20 * 30 / 10
70
>>> (10 + 20 * 30) / 10
61
>>> (10 + 20) * 30 / 10
90
>>> 2 + 2 == 4
True
>>> 2 + (2 == 4)
2
© SkillBrew http://skillbrew.com
Operator precedence (3)
14
When in doubt always use round brackets ()
© SkillBrew http://skillbrew.com
Summary
 Comparison operators
 Logical operators
 Bitwise operators
 Short-hand operators
 Increment and decrement
 Operator precedence
15
© SkillBrew http://skillbrew.com
Resources
 Increment and decrement behavior
http://stackoverflow.com/questions/1485841/behaviour-of-
increment-and-decrement-operators-in-python
 Tutorial on numbers
http://www.tutorialspoint.com/python/python_numbers.htm
16
17

More Related Content

What's hot (20)

PDF
Of Harmony and Stinginess: Applicative, Monad, and iterative library design
jspha
 
PPTX
Python Programming Essentials - M37 - Brief Overview of Misc Concepts
P3 InfoTech Solutions Pvt. Ltd.
 
PPTX
EcmaScript unchained
Eduard Tomàs
 
PDF
Introduction to Swift programming language.
Icalia Labs
 
PDF
C++ L11-Polymorphism
Mohammad Shaker
 
PPTX
Python Programming Essentials - M35 - Iterators & Generators
P3 InfoTech Solutions Pvt. Ltd.
 
PPTX
Python Programming Essentials - M27 - Logging module
P3 InfoTech Solutions Pvt. Ltd.
 
PPTX
Namespaces
zindadili
 
PDF
C++ L01-Variables
Mohammad Shaker
 
PDF
Time for Functions
simontcousins
 
PDF
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
ssuserd6b1fd
 
PPTX
Python Programming Essentials - M39 - Unit Testing
P3 InfoTech Solutions Pvt. Ltd.
 
PDF
Lecture 4
sajidpk92
 
PDF
Introduction to ES2015
kiranabburi
 
PPTX
Nested loops
Neeru Mittal
 
PDF
Thirteen ways of looking at a turtle
Scott Wlaschin
 
PPT
Practical Ext JS Debugging
Shea Frederick
 
PPT
C++ control loops
pratikborsadiya
 
PPTX
Python Programming Essentials - M9 - String Formatting
P3 InfoTech Solutions Pvt. Ltd.
 
PDF
Mutation Testing with PIT
Rafał Leszko
 
Of Harmony and Stinginess: Applicative, Monad, and iterative library design
jspha
 
Python Programming Essentials - M37 - Brief Overview of Misc Concepts
P3 InfoTech Solutions Pvt. Ltd.
 
EcmaScript unchained
Eduard Tomàs
 
Introduction to Swift programming language.
Icalia Labs
 
C++ L11-Polymorphism
Mohammad Shaker
 
Python Programming Essentials - M35 - Iterators & Generators
P3 InfoTech Solutions Pvt. Ltd.
 
Python Programming Essentials - M27 - Logging module
P3 InfoTech Solutions Pvt. Ltd.
 
Namespaces
zindadili
 
C++ L01-Variables
Mohammad Shaker
 
Time for Functions
simontcousins
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
ssuserd6b1fd
 
Python Programming Essentials - M39 - Unit Testing
P3 InfoTech Solutions Pvt. Ltd.
 
Lecture 4
sajidpk92
 
Introduction to ES2015
kiranabburi
 
Nested loops
Neeru Mittal
 
Thirteen ways of looking at a turtle
Scott Wlaschin
 
Practical Ext JS Debugging
Shea Frederick
 
C++ control loops
pratikborsadiya
 
Python Programming Essentials - M9 - String Formatting
P3 InfoTech Solutions Pvt. Ltd.
 
Mutation Testing with PIT
Rafał Leszko
 

Similar to Python Programming Essentials - M11 - Comparison and Logical Operators (20)

PPTX
PYTHON OPERATORS 123Python Operators.pptx
AnjaneyuluKunchala1
 
PPT
hlukj6;lukm,t.mnjhgjukryopkiu;lyk y2.ppt
PraveenaFppt
 
PDF
Python Operators.pdf
SudhanshiBakre1
 
PPTX
Operators in Python
Anusuya123
 
PPT
Py-Slides-2 (1).ppt
KalaiVani395886
 
PPT
Py-Slides-2.ppt
TejaValmiki
 
PPT
Py-Slides-2.ppt
AllanGuevarra1
 
PDF
Python : basic operators
S.M. Salaquzzaman
 
PPTX
Python programming language introduction unit
michaelaaron25322
 
PPTX
python statement, expressions and operators.pptx
richumt
 
PPTX
Session 4.pptx
YogeshwariK10
 
PPTX
Data Handling
bharath916489
 
PPTX
Python tutorials for beginners | IQ Online Training
Rahul Tandale
 
PPT
python operators.ppt
ErnieAcuna
 
PPTX
Python Lec-6 Operatorguijjjjuugggggs.pptx
ks812227
 
PPTX
Python Programming | JNTUK | UNIT 1 | Lecture 5
FabMinds
 
PPTX
OPERATOR IN PYTHON-PART2
vikram mahendra
 
PPTX
python operators.pptx
irsatanoli
 
PDF
ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2
prasadmutkule1
 
PYTHON OPERATORS 123Python Operators.pptx
AnjaneyuluKunchala1
 
hlukj6;lukm,t.mnjhgjukryopkiu;lyk y2.ppt
PraveenaFppt
 
Python Operators.pdf
SudhanshiBakre1
 
Operators in Python
Anusuya123
 
Py-Slides-2 (1).ppt
KalaiVani395886
 
Py-Slides-2.ppt
TejaValmiki
 
Py-Slides-2.ppt
AllanGuevarra1
 
Python : basic operators
S.M. Salaquzzaman
 
Python programming language introduction unit
michaelaaron25322
 
python statement, expressions and operators.pptx
richumt
 
Session 4.pptx
YogeshwariK10
 
Data Handling
bharath916489
 
Python tutorials for beginners | IQ Online Training
Rahul Tandale
 
python operators.ppt
ErnieAcuna
 
Python Lec-6 Operatorguijjjjuugggggs.pptx
ks812227
 
Python Programming | JNTUK | UNIT 1 | Lecture 5
FabMinds
 
OPERATOR IN PYTHON-PART2
vikram mahendra
 
python operators.pptx
irsatanoli
 
ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2
prasadmutkule1
 
Ad

More from P3 InfoTech Solutions Pvt. Ltd. (20)

PPTX
Python Programming Essentials - M44 - Overview of Web Development
P3 InfoTech Solutions Pvt. Ltd.
 
PPTX
Python Programming Essentials - M40 - Invoking External Programs
P3 InfoTech Solutions Pvt. Ltd.
 
PPTX
Python Programming Essentials - M34 - List Comprehensions
P3 InfoTech Solutions Pvt. Ltd.
 
PPTX
Python Programming Essentials - M29 - Python Interpreter and Files
P3 InfoTech Solutions Pvt. Ltd.
 
PPTX
Python Programming Essentials - M28 - Debugging with pdb
P3 InfoTech Solutions Pvt. Ltd.
 
PPTX
Python Programming Essentials - M25 - os and sys modules
P3 InfoTech Solutions Pvt. Ltd.
 
PPTX
Python Programming Essentials - M24 - math module
P3 InfoTech Solutions Pvt. Ltd.
 
PPTX
Python Programming Essentials - M23 - datetime module
P3 InfoTech Solutions Pvt. Ltd.
 
PPTX
Python Programming Essentials - M22 - File Operations
P3 InfoTech Solutions Pvt. Ltd.
 
PPTX
Python Programming Essentials - M21 - Exception Handling
P3 InfoTech Solutions Pvt. Ltd.
 
PPTX
Python Programming Essentials - M20 - Classes and Objects
P3 InfoTech Solutions Pvt. Ltd.
 
PPTX
Python Programming Essentials - M19 - Namespaces, Global Variables and Docstr...
P3 InfoTech Solutions Pvt. Ltd.
 
PPTX
Python Programming Essentials - M18 - Modules and Packages
P3 InfoTech Solutions Pvt. Ltd.
 
PPTX
Python Programming Essentials - M17 - Functions
P3 InfoTech Solutions Pvt. Ltd.
 
PPTX
Python Programming Essentials - M16 - Control Flow Statements and Loops
P3 InfoTech Solutions Pvt. Ltd.
 
PPTX
Python Programming Essentials - M15 - References
P3 InfoTech Solutions Pvt. Ltd.
 
PPTX
Python Programming Essentials - M14 - Dictionaries
P3 InfoTech Solutions Pvt. Ltd.
 
PPTX
Python Programming Essentials - M13 - Tuples
P3 InfoTech Solutions Pvt. Ltd.
 
PPTX
Python Programming Essentials - M12 - Lists
P3 InfoTech Solutions Pvt. Ltd.
 
PPTX
Python Programming Essentials - M8 - String Methods
P3 InfoTech Solutions Pvt. Ltd.
 
Python Programming Essentials - M44 - Overview of Web Development
P3 InfoTech Solutions Pvt. Ltd.
 
Python Programming Essentials - M40 - Invoking External Programs
P3 InfoTech Solutions Pvt. Ltd.
 
Python Programming Essentials - M34 - List Comprehensions
P3 InfoTech Solutions Pvt. Ltd.
 
Python Programming Essentials - M29 - Python Interpreter and Files
P3 InfoTech Solutions Pvt. Ltd.
 
Python Programming Essentials - M28 - Debugging with pdb
P3 InfoTech Solutions Pvt. Ltd.
 
Python Programming Essentials - M25 - os and sys modules
P3 InfoTech Solutions Pvt. Ltd.
 
Python Programming Essentials - M24 - math module
P3 InfoTech Solutions Pvt. Ltd.
 
Python Programming Essentials - M23 - datetime module
P3 InfoTech Solutions Pvt. Ltd.
 
Python Programming Essentials - M22 - File Operations
P3 InfoTech Solutions Pvt. Ltd.
 
Python Programming Essentials - M21 - Exception Handling
P3 InfoTech Solutions Pvt. Ltd.
 
Python Programming Essentials - M20 - Classes and Objects
P3 InfoTech Solutions Pvt. Ltd.
 
Python Programming Essentials - M19 - Namespaces, Global Variables and Docstr...
P3 InfoTech Solutions Pvt. Ltd.
 
Python Programming Essentials - M18 - Modules and Packages
P3 InfoTech Solutions Pvt. Ltd.
 
Python Programming Essentials - M17 - Functions
P3 InfoTech Solutions Pvt. Ltd.
 
Python Programming Essentials - M16 - Control Flow Statements and Loops
P3 InfoTech Solutions Pvt. Ltd.
 
Python Programming Essentials - M15 - References
P3 InfoTech Solutions Pvt. Ltd.
 
Python Programming Essentials - M14 - Dictionaries
P3 InfoTech Solutions Pvt. Ltd.
 
Python Programming Essentials - M13 - Tuples
P3 InfoTech Solutions Pvt. Ltd.
 
Python Programming Essentials - M12 - Lists
P3 InfoTech Solutions Pvt. Ltd.
 
Python Programming Essentials - M8 - String Methods
P3 InfoTech Solutions Pvt. Ltd.
 
Ad

Recently uploaded (20)

PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 

Python Programming Essentials - M11 - Comparison and Logical Operators

Editor's Notes

  • #3: Comparison operators allow you to compare two values.
  • #4: Comparison operators allow you to compare two values.
  • #5: Logical operators compare Boolean expressions and return a Boolean result. A boolean expression is an expression that results in a boolean value, that is, in a value of either true or false. More complex boolean expressions can be built out of simpler expressions, using the following boolean operators.
  • #6: Logical operators compare Boolean expressions and return a Boolean result. A boolean expression is an expression that results in a boolean value, that is, in a value of either true or false. More complex boolean expressions can be built out of simpler expressions, using the following boolean operators.
  • #7: A shorthand operator is a shorter way to express something that is already available in the programming language Shorthand operations do not add any feature to the programming language The intension here is to just walk through shorthand operators one by one
  • #8: The intension here is to just walk through shorthand operators one by one