
🐍 Lesson 6: Python Data Types (ဒေတာအမျိုးအစားများ)
1. Data Type ဆိုတာဘာလဲ?
မြန်မာ → Data Type ဆိုတာ Variable ထဲမှာ သိမ်းထားတဲ့ တန်ဖိုး (value) ရဲ့ အမျိုးအစားကို ဆိုလိုတယ်။
English → A data type defines the kind of value a variable holds.
2. Python ရဲ့ အဓိက Data Types
| Data Type | အမည် (မြန်မာ) | ဥပမာ |
|---|---|---|
| int (Integer) | ကိန်းပြည့် | age = 25 |
| float (Floating point) | ဒဿမကိန်း | pi = 3.14 |
| str (String) | စာသား | name = "Sai" |
| bool (Boolean) | အမှန်/အမှား | is_active = True |
3. Collection Types (အစုအဝေး Data Types)
| Data Type | အမည် (မြန်မာ) | Properties |
|---|---|---|
| list | စာရင်း | ordered, changeable |
| tuple | မပြောင်းလဲနိုင်တဲ့ စာရင်း | ordered, unchangeable |
| set | ထပ်မရှိတဲ့ အစု | unordered, no duplicates |
| dict (Dictionary) | Key-Value စုံ | key-value pairs, changeable |
4. Data Type ကို စစ်ဖို့
type()→ Variable ရဲ့ data type ကို ပြတယ်isinstance()→ Variable တစ်ခုက data type တစ်ခုနဲ့ ကိုက်မကိုက် စစ်နိုင်တယ်
5. အကျဉ်းချုပ်
✅ Data Type = Variable ထဲက တန်ဖိုးရဲ့ အမျိုးအစား
✅ အခြေခံ → int, float, str, bool
✅ Collection → list, tuple, set, dict
✅ စစ်ဖို့ → type(), isinstance()
python
# ===== 1. Basic Data Types Examples =====
# Integer
age = 25
print(f"Age: {age}, Type: {type(age)}")
# Float
pi = 3.14
print(f"Pi: {pi}, Type: {type(pi)}")
# String
name = "Sai"
print(f"Name: {name}, Type: {type(name)}")
# Boolean
is_active = True
print(f"Active: {is_active}, Type: {type(is_active)}")
print("\n===== 2. Collection Types =====")
# List
fruits = ["apple", "banana", "cherry"]
print(f"List: {fruits}, Type: {type(fruits)}")
# Tuple
colors = ("red", "green", "blue")
print(f"Tuple: {colors}, Type: {type(colors)}")
# Set
nums = {1, 2, 3, 3}
print(f"Set: {nums}, Type: {type(nums)}")
# Dictionary
person = {"name": "Sai", "age": 25}
print(f"Dict: {person}, Type: {type(person)}")
print("\n===== 3. Type Checking with isinstance() =====")
x = 10
print(f"x = {x}")
print(f"isinstance(x, int): {isinstance(x, int)}")
print(f"isinstance(x, float): {isinstance(x, float)}")You should see
Age: 25, Type: Pi: 3.14, Type: Name: Sai, Type: Active: True, Type: ===== 2. Collection Types ===== List: ['apple', 'banana', 'cherry'], Type: Tuple: ('red', 'green', 'blue'), Type: Set: {1, 2, 3}, Type: Dict: {'name': 'Sai', 'age': 25}, Type: ===== 3. Type Checking with isinstance() ===== x = 10 isinstance(x, int): True isinstance(x, float): False