SlideShare a Scribd company logo
PYTHON
OPERATORS
PRESENTED BY:ZAINAB NIAZ(7614)
AIMAN ELAHI (7612)
BSCS-_8th
PYTHON OPERATORS
Operators Symbols
“Operators are used to perform operations on variables and values”
python divides the operators in the following groups:
1. ARITHMETIC OPERATORS.
2. ASSIGNMENT OPERATORS.
3. COMPARISON OPERATORS.
4. LOGICAL OPERATORS.
5. IDENTITY OPERATORS.
6. MEMBERSHIP OPERATORS.
7. BITWISE OPERATORS.
1. PYTHON ARITHMETIC OPERATORS
“Arithmetic operators are used with numeric values to perform common
mathematical operations”
ADDITION(+)
EXAMPLE
X + Y
X = 5
Y = 3
PRINT(X + Y)
SUBTRACTION(-)
EXAMPLE
X – Y
X = 5
Y = 3
PRINT(X - Y)
MULTIPLICATION(*)
EXAMPLE
X * Y
X = 5
Y = 3
PRINT(X * Y)
…
DIVISION(/)
EXAMPLE
X / Y
X = 12
Y = 3
PRINT(X / Y)
MODULUS(%)
EXAMPLE
X % Y
X = 5
Y = 2
PRINT(X % Y)
…
EXPONENTIATION(**)
EXAMPLE
X ** Y
X = 2
Y = 5
PRINT(X ** Y)
#SAME AS 2*2*2*2*2
FLOOR DIVISION(//)
EXAMPLE
X // Y
X = 15
Y = 2
PRINT(X // Y)
#THE FLOOR DIVISION // ROUNDS THE RESULT DOWN TO
THE NEAREST WHOLE NUMBER
2. PYTHON ASSIGNMENT OPERATORS
Assignment operators are used to assign values to variables:
(ASSIGNS TO) (=) x=5
+=(ASSIGNMENT AFTER ADDITION)
EXAMPLE
X += 3
SAME AS: X = X + 3
X = 5
X += 3
PRINT(X)
-=(ASSIGNMENT AFTER SUBTRACTION)
EXAMPLE
X -= 3
SAME AS: X = X – 3
X = 5
X -= 3
PRINT(X)
*= (ASSIGNMENT AFTER MULTIPLICATION)
EXAMPLE
X *= 3
SAME AS: X = X * 3
X = 5
X *= 3
PRINT(X)
…
/=(ASSIGNMENT AFTER DIVISION)
EXAMPLE
X /= 3
SAME AS: X = X / 3
X = 5
X /= 3
PRINT(X)
%= (ASSIGNMENT AFTER MODULUS)
EXAMPLE
X %= 3
SAME AS: X = X % 3
X = 5
X%=3
PRINT(X)
…
**= (ASSIGNMENT AFTER EXPONENT)
EXAMPLE
X **= 3
SAME AS: X = X ** 3
X = 5
X **= 3
PRINT(X)
//= (ASSIGNMENT AFTER FLOOR DIVISION)
EXAMPLE
X //= 3
SAME AS: X = X // 3
X = 5
X//=3
PRINT(X)
3. PYTHON COMPARISON OPERATORS
“Comparison operators are used to comparing the value of the two operands and returns boolean
true or false accordingly”
EQUAL (==)
EXAMPLE
X == Y
X = 5
Y = 3
PRINT(X == Y)
# RETURNS FALSE BECAUSE 5 IS NOT EQUAL
TO 3
NOT EQUAL (!=)
EXAMPLE
X != Y
X = 5
Y = 3
PRINT(X != Y)
# RETURNS TRUE BECAUSE 5 IS NOT EQUAL
TO 3
…
GREATER THAN (>)
EXAMPLE
X > Y
X = 5
Y = 3
PRINT(X > Y)
# RETURNS TRUE BECAUSE 5 IS GREATER
THAN 3
LESS THAN (<)
EXAMPLE
X < Y
X = 5
Y = 3
PRINT(X < Y)
# RETURNS FALSE BECAUSE 5 IS NOT LESS
THAN 3
…
GREATER THAN OR EQUAL TO
(>=)
EXAMPLE
X >= Y
X = 5
Y = 3
PRINT(X >= Y)
# RETURNS TRUE BECAUSE FIVE IS GREATER
THAN 3
LESS THAN OR EQUAL TO
(<=)
EXAMPLE
X <= Y
X = 5
Y = 3
PRINT(X <= Y)
# RETURNS FALSE BECAUSE 5 IS NEITHER
LESS THAN 3
4. PYTHON LOGICAL OPERATORS
Logical operators are used to combine conditional statements
OR
The logical operators are used primarily in the expression evaluation to make a decision
AND (LOGICAL AND)
Returns true if both statements are true
EXAMPLE
X < 5 AND X < 10
x = 5
print(x > 3 and x < 10)
# returns True because 5 is greater than 3 AND 5 is less than 10
…
OR (LOGICAL OR)
Returns true if one of the statements is true
EXAMPLE
X < 5 OR X < 4
X = 5
PRINT(X > 3 OR X < 4)
# RETURNS TRUE BECAUSE ONE OF THE CONDITIONS ARE TRUE (5 IS GREATER THAN 3,
BUT 5 IS NOT LESS THAN 4)
…
NOT (LOGICAL NOT)
Reverse the result, returns false if the result is true
EXAMPLE
NOT(X < 5 AND X < 10)
X = 5
PRINT(NOT(X > 3 AND X < 10))
# RETURNS FALSE BECAUSE NOT IS USED TO REVERSE THE RESULT
PYTHON OPERATORS
• IDENTITY OPERATORS
• MEMBERSHIP OPERATORS
• BITWISE OPERATORS
5. PYTHON IDENTITY OPERATORS
• Identity operators are used to compare the objects, not if they are equal, but if
they are actually the same object, with the same memory location
Operator Description Example
is
Returns true if both
variables are the same
object
x is y
is not
Returns true if both
variables are not the
same object
x is not y
EXAMPLE:
6. PYTHON MEMBERSHIP OPERATORS
• MEMBERSHIP OPERATORS ARE USED TO TEST IF A SEQUENCE IS
PRESENTED IN AN OBJECT:
Operator Description Example
in
Returns True if a sequence
with the specified value is
present in the object
x in y
not in
Returns True if a sequence
with the specified value is
not present in the object
x not in y
EXAMPLE:
7. PYTHON BITWISE OPERATORS
• BITWISE OPERATORS ARE USED TO COMPARE (BINARY) NUMBERS
Operator Name Description
& AND Sets each bit to 1 if both bits are 1
| OR Sets each bit to 1 if one of two bits is 1
^ XOR Sets each bit to 1 if only one of two bits is 1
~ NOT Inverts all the bits
<< Zero fill left
shift
Shift left by pushing zeros in from the right and let the leftmost bits
fall off
>> Signed
right shift
Shift right by pushing copies of the leftmost bit in from the left, and
let the rightmost bits fall off
python operators.pptx
python operators.pptx
python operators.pptx
THANKYOU

More Related Content

PPTX
Chapter 5 Basic operators in programming
PDF
Operators in python
PPTX
Python Training in Bangalore | Python Operators | Learnbay.in
PPTX
Python operators
PPTX
Operators in python
PPTX
Operators in Python
PPTX
Python Operators
PPTX
Python operators
Chapter 5 Basic operators in programming
Operators in python
Python Training in Bangalore | Python Operators | Learnbay.in
Python operators
Operators in python
Operators in Python
Python Operators
Python operators

What's hot (19)

PPT
C Sharp Jn (2)
PPTX
How to use vlookup in MS Excel
PDF
Operators in python
PPTX
Basic c operators
PDF
Python : basic operators
PPTX
Vlookup - an introduction
PPTX
Supplement 13.1 blitzer tm4th
PPT
Arithmetic operator
PPTX
Operator of C language
PPTX
How to use Hlookup find an exact match
PPTX
Operators in java
PDF
itft-Operators in java
PPTX
C OPERATOR
PDF
VLOOKUP Function - Marelen Talavera - Vivacious Analytic
PPT
Operators
PPT
PPTX
Operator in c programming
PPTX
Operators and Expressions
PPTX
Operators in Java
C Sharp Jn (2)
How to use vlookup in MS Excel
Operators in python
Basic c operators
Python : basic operators
Vlookup - an introduction
Supplement 13.1 blitzer tm4th
Arithmetic operator
Operator of C language
How to use Hlookup find an exact match
Operators in java
itft-Operators in java
C OPERATOR
VLOOKUP Function - Marelen Talavera - Vivacious Analytic
Operators
Operator in c programming
Operators and Expressions
Operators in Java
Ad

Similar to python operators.pptx (20)

PPTX
Python assignment 1 Biswajit Mohapatra.pptx
PPTX
Python Lec-6 Operatorguijjjjuugggggs.pptx
PPTX
Understanding All Types of Operators in Python with Examples"
PPTX
python statement, expressions and operators.pptx
PPT
python operators.ppt
PPTX
Python programming language introduction unit
PPTX
Python Programming | JNTUK | UNIT 1 | Lecture 5
PPTX
Data types and operators
PPTX
OPERATORS-PYTHON.pptx ALL OPERATORS ARITHMATIC AND LOGICAL
PPTX
OPERATOR IN PYTHON-PART2
PPTX
PYTHON OPERATORS 123Python Operators.pptx
PPTX
operatorsinpython-18112209560412 (1).pptx
PPT
hlukj6;lukm,t.mnjhgjukryopkiu;lyk y2.ppt
PPT
Py-Slides-2 (1).ppt
PPT
Py-Slides-2.ppt
PPT
Py-Slides-2.ppt
PPTX
Different Types of Operators in Python.pptx
PPTX
Operators Concept in Python-N.Kavitha.pptx
PPTX
Python_Operations - types of the operators
PPTX
Python.pptx
Python assignment 1 Biswajit Mohapatra.pptx
Python Lec-6 Operatorguijjjjuugggggs.pptx
Understanding All Types of Operators in Python with Examples"
python statement, expressions and operators.pptx
python operators.ppt
Python programming language introduction unit
Python Programming | JNTUK | UNIT 1 | Lecture 5
Data types and operators
OPERATORS-PYTHON.pptx ALL OPERATORS ARITHMATIC AND LOGICAL
OPERATOR IN PYTHON-PART2
PYTHON OPERATORS 123Python Operators.pptx
operatorsinpython-18112209560412 (1).pptx
hlukj6;lukm,t.mnjhgjukryopkiu;lyk y2.ppt
Py-Slides-2 (1).ppt
Py-Slides-2.ppt
Py-Slides-2.ppt
Different Types of Operators in Python.pptx
Operators Concept in Python-N.Kavitha.pptx
Python_Operations - types of the operators
Python.pptx
Ad

Recently uploaded (20)

PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Digital Systems & Binary Numbers (comprehensive )
PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
DOCX
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
PDF
Autodesk AutoCAD Crack Free Download 2025
PDF
iTop VPN Crack Latest Version Full Key 2025
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
CapCut Video Editor 6.8.1 Crack for PC Latest Download (Fully Activated) 2025
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PPTX
assetexplorer- product-overview - presentation
PPTX
Weekly report ppt - harsh dattuprasad patel.pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Complete Guide to Website Development in Malaysia for SMEs
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
AutoCAD Professional Crack 2025 With License Key
PDF
Cost to Outsource Software Development in 2025
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Digital Systems & Binary Numbers (comprehensive )
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
Odoo Companies in India – Driving Business Transformation.pdf
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
Autodesk AutoCAD Crack Free Download 2025
iTop VPN Crack Latest Version Full Key 2025
CHAPTER 2 - PM Management and IT Context
CapCut Video Editor 6.8.1 Crack for PC Latest Download (Fully Activated) 2025
Oracle Fusion HCM Cloud Demo for Beginners
assetexplorer- product-overview - presentation
Weekly report ppt - harsh dattuprasad patel.pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Complete Guide to Website Development in Malaysia for SMEs
Reimagine Home Health with the Power of Agentic AI​
Designing Intelligence for the Shop Floor.pdf
AutoCAD Professional Crack 2025 With License Key
Cost to Outsource Software Development in 2025

python operators.pptx

  • 2. PYTHON OPERATORS Operators Symbols “Operators are used to perform operations on variables and values” python divides the operators in the following groups: 1. ARITHMETIC OPERATORS. 2. ASSIGNMENT OPERATORS. 3. COMPARISON OPERATORS. 4. LOGICAL OPERATORS. 5. IDENTITY OPERATORS. 6. MEMBERSHIP OPERATORS. 7. BITWISE OPERATORS.
  • 3. 1. PYTHON ARITHMETIC OPERATORS “Arithmetic operators are used with numeric values to perform common mathematical operations” ADDITION(+) EXAMPLE X + Y X = 5 Y = 3 PRINT(X + Y) SUBTRACTION(-) EXAMPLE X – Y X = 5 Y = 3 PRINT(X - Y) MULTIPLICATION(*) EXAMPLE X * Y X = 5 Y = 3 PRINT(X * Y)
  • 4. … DIVISION(/) EXAMPLE X / Y X = 12 Y = 3 PRINT(X / Y) MODULUS(%) EXAMPLE X % Y X = 5 Y = 2 PRINT(X % Y)
  • 5. … EXPONENTIATION(**) EXAMPLE X ** Y X = 2 Y = 5 PRINT(X ** Y) #SAME AS 2*2*2*2*2 FLOOR DIVISION(//) EXAMPLE X // Y X = 15 Y = 2 PRINT(X // Y) #THE FLOOR DIVISION // ROUNDS THE RESULT DOWN TO THE NEAREST WHOLE NUMBER
  • 6. 2. PYTHON ASSIGNMENT OPERATORS Assignment operators are used to assign values to variables: (ASSIGNS TO) (=) x=5 +=(ASSIGNMENT AFTER ADDITION) EXAMPLE X += 3 SAME AS: X = X + 3 X = 5 X += 3 PRINT(X) -=(ASSIGNMENT AFTER SUBTRACTION) EXAMPLE X -= 3 SAME AS: X = X – 3 X = 5 X -= 3 PRINT(X) *= (ASSIGNMENT AFTER MULTIPLICATION) EXAMPLE X *= 3 SAME AS: X = X * 3 X = 5 X *= 3 PRINT(X)
  • 7. … /=(ASSIGNMENT AFTER DIVISION) EXAMPLE X /= 3 SAME AS: X = X / 3 X = 5 X /= 3 PRINT(X) %= (ASSIGNMENT AFTER MODULUS) EXAMPLE X %= 3 SAME AS: X = X % 3 X = 5 X%=3 PRINT(X)
  • 8. … **= (ASSIGNMENT AFTER EXPONENT) EXAMPLE X **= 3 SAME AS: X = X ** 3 X = 5 X **= 3 PRINT(X) //= (ASSIGNMENT AFTER FLOOR DIVISION) EXAMPLE X //= 3 SAME AS: X = X // 3 X = 5 X//=3 PRINT(X)
  • 9. 3. PYTHON COMPARISON OPERATORS “Comparison operators are used to comparing the value of the two operands and returns boolean true or false accordingly” EQUAL (==) EXAMPLE X == Y X = 5 Y = 3 PRINT(X == Y) # RETURNS FALSE BECAUSE 5 IS NOT EQUAL TO 3 NOT EQUAL (!=) EXAMPLE X != Y X = 5 Y = 3 PRINT(X != Y) # RETURNS TRUE BECAUSE 5 IS NOT EQUAL TO 3
  • 10. … GREATER THAN (>) EXAMPLE X > Y X = 5 Y = 3 PRINT(X > Y) # RETURNS TRUE BECAUSE 5 IS GREATER THAN 3 LESS THAN (<) EXAMPLE X < Y X = 5 Y = 3 PRINT(X < Y) # RETURNS FALSE BECAUSE 5 IS NOT LESS THAN 3
  • 11. … GREATER THAN OR EQUAL TO (>=) EXAMPLE X >= Y X = 5 Y = 3 PRINT(X >= Y) # RETURNS TRUE BECAUSE FIVE IS GREATER THAN 3 LESS THAN OR EQUAL TO (<=) EXAMPLE X <= Y X = 5 Y = 3 PRINT(X <= Y) # RETURNS FALSE BECAUSE 5 IS NEITHER LESS THAN 3
  • 12. 4. PYTHON LOGICAL OPERATORS Logical operators are used to combine conditional statements OR The logical operators are used primarily in the expression evaluation to make a decision AND (LOGICAL AND) Returns true if both statements are true EXAMPLE X < 5 AND X < 10 x = 5 print(x > 3 and x < 10) # returns True because 5 is greater than 3 AND 5 is less than 10
  • 13. … OR (LOGICAL OR) Returns true if one of the statements is true EXAMPLE X < 5 OR X < 4 X = 5 PRINT(X > 3 OR X < 4) # RETURNS TRUE BECAUSE ONE OF THE CONDITIONS ARE TRUE (5 IS GREATER THAN 3, BUT 5 IS NOT LESS THAN 4)
  • 14. … NOT (LOGICAL NOT) Reverse the result, returns false if the result is true EXAMPLE NOT(X < 5 AND X < 10) X = 5 PRINT(NOT(X > 3 AND X < 10)) # RETURNS FALSE BECAUSE NOT IS USED TO REVERSE THE RESULT
  • 15. PYTHON OPERATORS • IDENTITY OPERATORS • MEMBERSHIP OPERATORS • BITWISE OPERATORS
  • 16. 5. PYTHON IDENTITY OPERATORS • Identity operators are used to compare the objects, not if they are equal, but if they are actually the same object, with the same memory location Operator Description Example is Returns true if both variables are the same object x is y is not Returns true if both variables are not the same object x is not y
  • 18. 6. PYTHON MEMBERSHIP OPERATORS • MEMBERSHIP OPERATORS ARE USED TO TEST IF A SEQUENCE IS PRESENTED IN AN OBJECT: Operator Description Example in Returns True if a sequence with the specified value is present in the object x in y not in Returns True if a sequence with the specified value is not present in the object x not in y
  • 20. 7. PYTHON BITWISE OPERATORS • BITWISE OPERATORS ARE USED TO COMPARE (BINARY) NUMBERS Operator Name Description & AND Sets each bit to 1 if both bits are 1 | OR Sets each bit to 1 if one of two bits is 1 ^ XOR Sets each bit to 1 if only one of two bits is 1 ~ NOT Inverts all the bits << Zero fill left shift Shift left by pushing zeros in from the right and let the leftmost bits fall off >> Signed right shift Shift right by pushing copies of the leftmost bit in from the left, and let the rightmost bits fall off