🐍 Lesson 9: Python Strings (Python စာသား)
1. String ဆိုတာဘာလဲ?
မြန်မာ → String ဆိုတာ စာလုံး၊ စာကြောင်း၊ စာသားတွေကို သိမ်းထားတဲ့ Data Type ဖြစ်တယ်။
English → A string is a sequence of characters enclosed in quotes.
2. String Methods (အသုံးများတဲ့ Method များ)
upper()→ စာလုံးအကြီး ပြောင်းlower()→ စာလုံးအသေး ပြောင်းstrip()→ အရှေ့နဲ့ အနောက် space ဖယ်replace(a, b)→ a ကို b နဲ့ အစားထိုးsplit()→ စာကြောင်းကို စာရင်းအဖြစ် ခွဲ
3. String Formatting
Variable တွေကို string ထဲထည့်ချင်ရင် f-string သုံးရလွယ်တယ်
4. အကျဉ်းချုပ်
✅ String = စာသား Data Type
✅ Indexing, slicing နဲ့ စာလုံးတွေကို ခေါ်နိုင်
✅ Method တွေ (upper, lower, strip, replace, split) အသုံးများ
✅ f-string သုံးပြီး စာသားတွဲနိုင်
python
# ===== 1. String Creation =====
a = 'Hello'
b = "World"
c = """This is
a multi-line
string"""
print(f"Single quotes: {a}")
print(f"Double quotes: {b}")
print(f"Multi-line: {c}")
# ===== 2. String Indexing & Slicing =====
print(f"\n===== Indexing & Slicing =====")
text = "Python"
print(f"First character: {text[0]}") # P
print(f"Last character: {text[-1]}") # n
print(f"Slice [0:3]: {text[0:3]}") # Pyt
print(f"Slice [2:]: {text[2:]}") # thon
# ===== 3. String Methods =====
print(f"\n===== String Methods =====")
txt = " hello world "
print(f"Upper: {txt.upper()}")
print(f"Lower: {txt.lower()}")
print(f"Strip: '{txt.strip()}'")
print(f"Replace: {txt.replace('world', 'Python')}")
print(f"Split: {txt.split()}")
# ===== 4. String Formatting (f-strings) =====
print(f"\n===== String Formatting =====")
name = "Sai"
age = 25
print(f"My name is {name}, I am {age} years old.")
# ===== 5. String Length =====
print(f"\nLength of 'Python': {len('Python')}")You should see
Single quotes: Hello Double quotes: World Multi-line: This is a multi-line string ===== Indexing & Slicing ===== First character: P Last character: n Slice [0:3]: Pyt Slice [2:]: thon ===== String Methods ===== Upper: HELLO WORLD Lower: hello world Strip: 'hello world' Replace: hello Python Split: ['hello', 'world'] ===== String Formatting ===== My name is Sai, I am 25 years old. Length of 'Python': 6