Skip to main content
Albero Academy

Comments & Documentation

Write comments and docstrings that explain the why, and follow the conventions that keep code readable.

Fundamentals7 min

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.

comments and docstrings
# A single-line comment explains the reasoning
tax = price * 0.18 # 18% GST, per 2026 rate
def area(radius):
"""Return the area of a circle with the given radius.""" # docstring
return 3.14159 * radius ** 2
help(area) # shows the docstring

Key takeaways

  1. 01Use # for single-line comments; explain intent, not the obvious.
  2. 02Docstrings ("""…""") document functions/modules and power help().
  3. 03Comment the why and the trade-offs, not a restatement of the code.
  4. 04Readable code plus a good docstring beats a wall of comments.

Finished this chapter?

Mark it complete to track your progress through Python.