🐍 Lesson 56: Python Built-in Functions
1. Built-in Functions ဆိုတာဘာလဲ?
မြန်မာ → Python မှာ အခြေခံအဆင့် functions အများကြီး built-in အနေနဲ့ ပါပြီးသား။ Developer တွေက import မလုပ်ဘဲ တိုက်ရိုက်သုံးနိုင်တယ်။
English → Built-in functions are pre-defined functions in Python that can be used directly without importing any library.
2. Commonly Used Built-in Functions
| print() | Output ကို screen ပေါ်မှာ ပြမယ် |
|---|---|
| len() | String, list, dict စတာတွေရဲ့ length ကိုတွက်မယ် |
| type() | Data type ကို ပြမယ် |
| max(), min() | အကြီးဆုံး/အသေးဆုံး value |
| sum() | List ထဲက numbers တွေကို စုချုပ်တွက်မယ် |
| sorted() | List ကို စဉ်လိုက်စီမယ် |
3. အကျဉ်းချုပ်
✅ Python built-in functions = import မလိုဘဲ တိုက်ရိုက်သုံးနိုင်တယ်
✅ အခြေခံ → print(), len(), type(), sum()
✅ အဆင့်မြင့် → map(), filter(), zip(), enumerate()
✅ Data analysis, iteration, conversion အတွက် အသုံးဝင်တယ်
python
# ===== 1. Basic Built-in Functions =====
numbers = [10, 20, 5, 40]
print("===== Basic Functions =====")
print(f"Length: {len(numbers)}") # 4
print(f"Max: {max(numbers)}") # 40
print(f"Min: {min(numbers)}") # 5
print(f"Sum: {sum(numbers)}") # 75
print(f"Sorted: {sorted(numbers)}") # [5, 10, 20, 40]
# ===== 2. Type Conversion =====
print(f"\n===== Type Conversion =====")
print(f"int('5'): {int('5')}")
print(f"float('3.14'): {float('3.14')}")
print(f"str(123): {str(123)}")
print(f"type(123): {type(123)}")
# ===== 3. String Functions =====
print(f"\n===== String Functions =====")
text = "Python"
print(f"len('{text}'): {len(text)}")
print(f"max('{text}'): {max(text)}")
print(f"min('{text}'): {min(text)}")
# ===== 4. Advanced Functions =====
print(f"\n===== Advanced Functions =====")
# map()
nums = [1, 2, 3, 4]
squares = list(map(lambda x: x**2, nums))
print(f"map(lambda x: x**2, [1,2,3,4]): {squares}")
# filter()
evens = list(filter(lambda x: x % 2 == 0, nums))
print(f"filter(lambda x: x % 2 == 0, [1,2,3,4]): {evens}")
# zip()
names = ["Sai", "Aye"]
ages = [25, 22]
combined = list(zip(names, ages))
print(f"zip(['Sai','Aye'], [25,22]): {combined}")
# enumerate()
for i, name in enumerate(names):
print(f"enumerate: {i} = {name}")You should see
===== Basic Functions ===== Length: 4 Max: 40 Min: 5 Sum: 75 Sorted: [5, 10, 20, 40] ===== Type Conversion ===== int('5'): 5 float('3.14'): 3.14 str(123): '123' type(123): ===== String Functions ===== len('Python'): 6 max('Python'): 'y' min('Python'): 'P' ===== Advanced Functions ===== map(lambda x: x**2, [1,2,3,4]): [1, 4, 9, 16] filter(lambda x: x % 2 == 0, [1,2,3,4]): [2, 4] zip(['Sai','Aye'], [25,22]): [('Sai', 25), ('Aye', 22)] enumerate: 0 = Sai enumerate: 1 = Aye