Python Operators
Mastering the Building Blocks of Python
What Are Operators?
Operators are symbols that perform operations on variables and values.
Example: x + y
Arithmetic Operators
Examples:
5+3=8
2 ** 3 = 8
Assignment Operators
Examples:
x=5
x += 3 # Now x is 8
Comparison Operators
Examples:
a = 10
b = 20
a < b # True
Logical Operators
Examples:
x = True
y = False
x and y # False
Bitwise Operators
Examples:
a = 4 # 0100
b = 5 # 0101
a&b #4
Membership & Identity Operators
Examples:
x = [1, 2, 3]
2 in x # True
x is [1, 2, 3] # False
Operator Precedence
Example:
result = 3 + 4 * 2 # 11, not 14
Summary
Types covered:
- Arithmetic
- Assignment
- Comparison
- Logical
- Bitwise
- Membership & Identity
Quiz or Activity
Guess the output:
a=5
b = 10
print(a > b or a == 5) # True
Thank You!
Questions?