Python Operators (All Types with
Examples)
Arithmetic, Relational, Logical,
Assignment, Bitwise, Membership,
Identity
1. Arithmetic Operators
• Addition (+): 5 + 3 = 8
• Subtraction (-): 5 - 3 = 2
• Multiplication (*): 5 * 3 = 15
• Division (/): 5 / 2 = 2.5
• Modulus (%): 5 % 2 = 1
• Exponentiation (**): 2 ** 3 = 8
• Floor Division (//): 5 // 2 = 2
2. Relational Operators
• Equal to (==): 5 == 3 → False
• Not equal to (!=): 5 != 3 → True
• Greater than (>): 5 > 3 → True
• Less than (<): 5 < 3 → False
• Greater than or equal to (>=): 5 >= 5 → True
• Less than or equal to (<=): 3 <= 5 → True
3. Logical Operators
• AND (and): True and False → False
• OR (or): True or False → True
• NOT (not): not True → False
4. Assignment Operators
• =:a=5
• += : a += 3 (a = a + 3)
• -= : a -= 2 (a = a - 2)
• *= : a *= 2 (a = a * 2)
• /= : a /= 2 (a = a / 2)
• %= : a %= 2 (a = a % 2)
• **= : a **= 2 (a = a ** 2)
• //= : a //= 2 (a = a // 2)
5. Bitwise Operators
• & (AND): 5 & 3 = 1
• | (OR): 5 | 3 = 7
• ^ (XOR): 5 ^ 3 = 6
• ~ (NOT): ~5 = -6
• << (Left Shift): 5 << 1 = 10
• >> (Right Shift): 5 >> 1 = 2
6. Membership Operators
• 'a' in 'apple' → True
• 'x' not in 'apple' → True
7. Identity Operators
• is: a is b → True if a and b refer to same object
• is not: a is not b → True if a and b refer to
different objects
8. Final Combined Example
• Example:
• a = 5; b = 3
• if (a > b) and (a != b):
• print('a is greater and not equal to b') #
Logical + Relational
• c = a + b # Arithmetic
• a += 1 # Assignment
• print(c in [8, 9, 10]) # Membership
• print(a is b) # Identity