✅ Python Operators
🐍⚡ Operators help perform operations on variables and values.
🔹 1. Arithmetic Operators (Math Operations)
Used for calculations.
- Addition (5 + 2 = 7)
- Subtraction (5 - 2 = 3)
- Multiplication (5 * 2 = 10)
- Division (5 / 2 = 2.5)
- % Modulus (remainder) (5 % 2 = 1)
- Power (2 3 = 8)
- // Floor division (5 // 2 = 2)
✅ Example:
a = 10
b = 3
print(a + b)
print(a % b)
print(a ** b)
🔹 2. Comparison Operators (Return True/False)
Used for decision making.
- == Equal
- != Not equal
- > Greater than
- < Less than
- >= Greater or equal
- <= Less or equal
✅ Example:
x = 5
print(x > 3) # True
print(x == 5) # True
🔹 3. Logical Operators
Used to combine conditions.
- and: Both conditions true
- or: At least one true
- not: Reverse result
✅ Example:
age = 20
print(age > 18 and age < 30)
🔹 4. Assignment Operators
Used to assign values.
x = 5
x += 2 # x = x + 2
x -= 1
x *= 3
🔹 5. Practice (Must Try)
a = 15
b = 4
print(a + b)
print(a > b)
print(a % b)
print(a < 20 and b < 10)
🎯 Today’s Goal
✅ Learn arithmetic operations
✅ Understand comparisons (True/False)
✅ Use logical conditions
Double Tap ♥️ For More