🏠 Home / Hub

📦 Python Lesson 02 — Variables & Data Types

← Back to Python Menu

1. Variable

Variable ဆိုတာ data သိမ်းတဲ့ နာမည်ပေးထားတဲ့ box လိုပါပဲ။ Python မှာ type ကိုကြိုရေးစရာမလိုဘူး။

name = "Su Su"
age = 21
height = 5.4
is_student = True
address = None

2. Common Data Types

TypeExampleUse
str"Hello"Text
int100Whole number
float19.99Decimal number
boolTrue / FalseDecision
NoneTypeNoneNo value

3. type() စစ်ခြင်း

print(type("Hello"))   # <class 'str'>
print(type(100))       # <class 'int'>
print(type(3.14))      # <class 'float'>
print(type(True))      # <class 'bool'>
print(type(None))      # <class 'NoneType'>

4. Type Conversion

age_text = "20"
age = int(age_text)

price_text = "12.50"
price = float(price_text)

count = 5
message = "Total is " + str(count)
input() က string ပြန်ပေးတာမို့ number တွက်မယ်ဆို int() / float() ပြောင်းရမယ်။

5. String Formatting

name = "Mg Mg"
score = 85

print("Name:", name, "Score:", score)
print("Name is " + name)
print(f"{name} got {score} marks")  # recommended

6. Naming Rules

# Good
student_name = "Aye Aye"
total_price = 25000
is_active = True

# Bad
# 2name = "wrong"
# total-price = 100
# class = "reserved keyword"

📌 Study Checklist