Code says what happens; comments say why. Good comments explain intent and trade-offs — not the obvious. Python also has docstrings that document functions and modules.
# A single-line comment explains the reasoningtax = price * 0.18 # 18% GST, per 2026 ratedef area(radius):"""Return the area of a circle with the given radius.""" # docstringreturn 3.14159 * radius ** 2help(area) # shows the docstring
Key takeaways
- 01Use # for single-line comments; explain intent, not the obvious.
- 02Docstrings ("""…""") document functions/modules and power help().
- 03Comment the why and the trade-offs, not a restatement of the code.
- 04Readable code plus a good docstring beats a wall of comments.
