🐍 Lesson 4: Python Comments
1. What is a comment?
Short answer → A comment is a note written inside your Python code, and Python skips over it instead of running it.
In other words → A comment is a line in the code that is ignored by Python, used for notes or explanations.
2. Types of Comments
| Type | Syntax | အသုံးပြုပုံ |
|---|---|---|
| Single-line | # ဖြင့်စသည် | တစ်ကြောင်းတည်း comment |
| Multi-line | """...""" | စာကြောင်းများစွာ comment |
| Docstring | """...""" | Function/Class documentation |
3. Why use comments
- 📝 To make your code easier to understand
- 🕒 So you can quickly remember what's going on when you revisit it later
- 🚫 To temporarily disable a piece of code
4. Summary
✅ # → Single-line comment
✅ """...""" → Multi-line / Docstring
✅ Comments make your code easier to understand and matter a lot for documentation
python
# ===== 1. Single-line Comment =====
# ဒီလိုရေးရင် comment ဖြစ်တယ်
print("Hello") # ဒီလို inline comment လည်း ရ
# ===== 2. Multi-line Comment =====
"""
ဒီနေရာမှာ
စာကြောင်းများစွာ
comment အနေနဲ့ရေးနိုင်တယ်
"""
print("Hello World")
# ===== 3. Docstring Example =====
def greet(name):
"""
ဒီ function က နာမည်ထည့်ပြီး Hello ပြန်ပေးမယ်
Parameters:
name (str): လူရဲ့နာမည်
Returns:
str: Hello message
"""
return f"Hello {name}"
print(greet("Sai"))
# ===== 4. Temporarily Disable Code =====
# x = 10 # ဒီ code ကို အချိန်ပိုင်း disable လုပ်ထားတယ်
y = 20
print(f"Y value: {y}")You should see
Hello Hello World Hello Sai Y value: 20