UNDERSTANDING
PYTHON OPERATOR
A COMPREHENSIVE
GUIDE
PRESENTED BY
SARAN KIRUTHIK S S
11-08-2024
INTRODUCTION
• What are Python Operators?
• Operators are special symbols that perform operations on
variables and values.Importance: They form the backbone of
Python expressions, enabling everything from basic arithmetic to
complex data manipulation.
TYPES OF OPERATORS
• Overview of Python
• Arithmetic Operators
• Comparison (Relational) Operators
• Logical Operators
• Bitwise Operators
• Assignment Operators
• Identity Operators
• Membership Operators
A = 10 ARITHMETIC
OPERATORS
B=3 • + : Addition
• - : Subtraction
• * : Multiplication
PRINT(A + B) #
• / : Division
OUTPUT: 13
• % : Modulus
• ** : Exponentiation
PRINT(A ** B) #
• // : Floor Division
OUTPUT: 1000
COMPARISON
A=5 (RELATIONAL)
OPERATORS
B = 10 • == : Equal to
• != : Not equal to
• > : Greater than
PRINT(A == B) #
• < : Less than
OUTPUT: FALSE
• >= : Greater than or equal to
• <= : Less than or equal to
PRINT(A < B) #
OUTPUT: TRUE
X = TRUE
LOGICAL OPERATORS
Y = FALSE • and : Logical AND
• or : Logical OR
• not : Logical NOT
PRINT(X AND Y) #
OUTPUT: FALSE
PRINT(NOT X) #
OUTPUT: FALSE
A = 10 # 1010 IN
BINARY
BITWISE OPERATORS
• & : AND
B = 4 # 0100 IN
• | : OR
BINARY
• ^ : XOR
• ~ : NOT
PRINT(A & B) #
OUTPUT: 0 • << : Zero fill left shift
• >> : Signed right shift
PRINT(A | B) #
OUTPUT: 14
A=5 ASSIGNMENT
OPERATORS
A += 3 # A = A + 3 • = : Assign
• += : Add and assign
• -= : Subtract and assign
PRINT(A) #
• *= : Multiply and assign
OUTPUT
• /= : Divide and assign
• %=: M.odulus and assign
• **= : Exponent and assign//= : Floor divide and
assign
X = [1, 2, 3]
IDENTITY OPERATORS
Y=X
• is : Returns True if both variables are the same
object
Z = [1, 2, 3] • is not : Returns True if both variables are not the
same object
PRINT(X IS Y) #
OUTPUT: TRUE
PRINT(X IS Z) #
OUTPUT: FALSE
A = [1, 2, 3, 4, 5] MEMBERSHIP
OPERATORS
PRINT(3 IN A) # • in : Returns True if a sequence with the specified
value is present in the object
OUTPUT: TRUE
• not in : Returns True if a sequence with the
specified value is not present in the object
PRINT(6 NOT IN A)
# OUTPUT: TRUE
OPERATOR
PRECEDENCE
Explanation
Defines the order in which operations are performed.
Example: a + b * c multiplies b and c before adding a.
Realtime Example:
result = 2 + 3 * 4 - (5 ** 2) / 5
print(result) # Output:
PRACTICAL APPLICATIONS
• Mathematical computations
• Conditional statements
• Bitwise operations for performance optimization
• Data validation with identity and membership operators
SUMMARY
• Key Points:
• Python operators are essential for performing operations on data.
• Understanding different types of operators is crucial for writing effective Python
code
• Pay attention to operator precedence and common pitfalls.
Q&A SESSION
INVITE
QUESTIONS AND
CLARIFY ANY
DOUBTS
THANK YOU
FOR YOUR ATTENTION
+91 8072682003
[email protected]