🐍 Lesson 10: Python Booleans (အမှန် / အမှား)
1. Boolean ဆိုတာဘာလဲ?
မြန်မာ → Boolean ဆိုတာ Data Type တစ်မျိုးဖြစ်ပြီး အမှန် (True) နဲ့ အမှား (False) ဆိုတဲ့ တန်ဖိုးနှစ်မျိုးပဲ ရှိတယ်။
English → A Boolean is a data type that can only have two values: True or False.
2. Logical Operators
- and → နှစ်ခုလုံး True ဖြစ်မှသာ True
- or → တစ်ခုခု True ဖြစ်ရင် True
- not → တန်ဖိုးကို ပြောင်းပြန်
3. အကျဉ်းချုပ်
✅ Boolean = True / False
✅ Comparison နဲ့ Logical operators တွေမှာ အသုံးများ
✅ Empty values → False, Non-empty values → True
✅ 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