Logical Operators
Last Updated: 16th August 2025
Logical operators are used to combine conditional statements (expressions that return True/False).
They allow us to make complex decisions in code.
Hinglish Tip 🗣: Logical operators ko use karke aap multiple conditions ek saath check kar sakte ho.
✏ Syntax & Examples
a = 10
b = 20
print(a > 5 and b > 15) # True (both are True)
print(a > 5 or b < 10) # True (one condition is True)
print(not(a == 10)) # False (a == 10 is True, so not → False)
⚠️ Quick Notes
- and → True only if both sides are True.
- or → True if any one side is True.
- not → flips the result (True ↔ False).
- Python uses short-circuit evaluation:
- and stops if first condition is False.
- or stops if first condition is True.
Hinglish Tip 🗣: Short-circuit matlab Python unnecessary conditions check nahi karega agar pehle hi answer mil gaya.
- and with Truthy/Falsy Values:
💡 Quick Practice
- Write a condition: Check if a number n is between 10 and 20 using and.
- Use or to check if a number is negative or zero.
- Use not to invert the result of (5 > 10).
- Try (True and False) or True. Predict the result.
- Exercises
