🔹 1. What Are Operators?
Operators are symbols that perform operations on values or variables.
Example:
x = 10
y = 5
print(x + y) # 15
Here, + is the operator, and x and y are operands.

🔹 2. Types of Operators in Python
🧮 A. Arithmetic Operators
Used for mathematical operations.
| Operator | Description | Example | Output |
|---|---|---|---|
| + | Addition | 5 + 3 | 8 |
| - | Subtraction | 10 - 4 | 6 |
| * | Multiplication | 2 * 3 | 6 |
| / | Division | 10 / 3 | 3.333... |
| % | Modulus | 10 % 3 | 1 |
| ** | Exponentiation | 2 ** 3 | 8 |
| // | Floor Division | 10 // 3 | 3 |
Example:
a, b = 15, 4
print(a + b, a - b, a * b, a / b, a % b, a ** b, a // b)
⚖️ B. Comparison (Relational) Operators
Used to compare values — return True or False.
| Operator | Description | Example | Output |
|---|---|---|---|
| == | Equal to | 5 == 5 | True |
| != | Not equal to | 5 != 3 | True |
| > | Greater than | 10 > 2 | True |
| < | Less than | 3 < 5 | True |
| >= | Greater or equal | 10 >= 10 | True |
| <= | Less or equal | 7 <= 9 | True |
Example:
x, y = 7, 10
print(x > y, x == y, x != y)
💡 C. Logical Operators
Used to combine conditions.
| Operator | Description | Example | Output |
|---|---|---|---|
| and | True if both are true | (5 > 3) and (6 > 2) | True |
| or | True if at least one is true | (5 > 8) or (6 > 2) | True |
| not | Reverses condition | not(5 > 3) | False |
Example:
a, b = True, False
print(a and b, a or b, not a)
📦 D. Assignment Operators
Used to assign values to variables.
| Operator | Example | Equivalent To |
|---|---|---|
| = | x = 5 | x = 5 |
| += | x += 3 | x = x + 3 |
| -= | x -= 2 | x = x - 2 |
| *= | x *= 4 | x = x * 4 |
| /= | x /= 2 | x = x / 2 |
| %= | x %= 3 | x = x % 3 |
Example:
x = 10
x += 5
print(x) # 15
⚙️ E. Bitwise Operators
Work on binary numbers.
| Operator | Description | Example | Output |
|---|---|---|---|
| & | AND | 5 & 3 | 1 |
| OR | 5 | ||
| ^ | XOR | 5 ^ 3 | 6 |
| << | Left shift | 5 << 1 | 10 |
| >> | Right shift | 5 >> 1 | 2 |
Example:
a, b = 5, 3
print(a & b, a | b, a ^ b, a << 1, a >> 1)
# Note: 5 (0101), 3 (0011)
🧩 F. Membership Operators
Used to check if a value exists in a sequence.
| Operator | Description | Example | Output |
|---|---|---|---|
| in | True if found | 'a' in 'apple' | True |
| not in | True if not found | 'z' not in 'apple' | True |
Example:
fruits = ["apple", "banana", "mango"]
print("apple" in fruits)
🎯 G. Identity Operators
Compare memory locations of objects.
| Operator | Description | Example | Output |
|---|---|---|---|
| is | True if same object | x is y | True/False |
| is not | True if different | x is not y | True/False |
Example:
x = [1, 2, 3]
y = x
z = [1, 2, 3]
print(x is y) # True
print(x is z) # False
🔹 3. Expressions
An expression combines variables, constants, and operators to produce a value.

Example:
x = 10
y = 5
z = (x + y) * 2
print(z) # 30
🧠 Quick Practice Tasks
Arithmetic Practice: Input two numbers and show sum, difference, product, quotient, remainder.
Eligibility Checker: Ask user’s age → print “Adult” if ≥18 else “Minor”.
Password Validation: Check if “@” exists in entered password using in.
Bitwise Practice: Display binary representation and perform bitwise & and |.