🐍 Lesson 10: Python Booleans (True / False)
1. What is a Boolean?
In short → A Boolean is a data type with only two possible values: True and False.
More formally → A Boolean is a data type that can only have two values: True or False.
2. Logical Operators
- and → True only when both are True
- or → True if either one is True
- not → flips the value
3. Summary
✅ Boolean = True / False
✅ Commonly used in comparison and logical operators
✅ Empty values → False, Non-empty values → True
✅ Plays a key role in control flow (if...else)
python
# ===== 1. Boolean Values =====
x = True
y = False
print(f"x = {x}, Type: {type(x)}")
print(f"y = {y}, Type: {type(y)}")
# ===== 2. Comparison Operations =====
print(f"\n===== Comparison =====")
print(f"10 > 5 = {10 > 5}") # True
print(f"10 == 5 = {10 == 5}") # False
print(f"10 < 5 = {10 < 5}") # False
# ===== 3. Logical Operators =====
print(f"\n===== Logical Operators =====")
a = True
b = False
print(f"a and b = {a and b}") # False
print(f"a or b = {a or b}") # True
print(f"not a = {not a}") # False
# ===== 4. Boolean Values of Objects =====
print(f"\n===== Boolean of Objects =====")
print(f"bool(0) = {bool(0)}") # False
print(f"bool(1) = {bool(1)}") # True
print(f"bool('') = {bool('')}") # False
print(f"bool('Sai') = {bool('Sai')}") # True
print(f"bool([]) = {bool([])}") # False
print(f"bool([1,2,3]) = {bool([1,2,3])}") # TrueYou should see
x = True, Type: y = False, Type: ===== Comparison ===== 10 > 5 = True 10 == 5 = False 10 < 5 = False ===== Logical Operators ===== a and b = False a or b = True not a = False ===== Boolean of Objects ===== bool(0) = False bool(1) = True bool('') = False bool('Sai') = True bool([]) = False bool([1,2,3]) = True