Comments in Python

SyntaxVariables

Comments are notes in your code that Python ignores when running the program. They explain what the code does, making it easier to understand and maintain.

Good comments are essential for collaboration and for your future self.

Single-Line Comments

Start with # – everything after it on the line is ignored.

Multi-Line Comments

Python doesn't have a special syntax – use multiple # lines or triple quotes (often used for docstrings).

Docstrings – Documentation Strings

Triple quotes right after a function/class/module define a docstring – accessible via help() or __doc__.

When to Use Comments

  • Explain why code does something (not just what).
  • Document functions/classes with docstrings.
  • Temporarily disable code during testing.
  • Add TODO notes or section headers.

Avoid commenting obvious code – focus on clarity.

Quick Quiz

We have reviewed and checked the materials, but errors may still occur. The content is provided for educational purposes only, so use it at your own responsibility and verify with other sources if needed.

✨ Ask Lara — your AI study partner

Unlock personalized learning support. Lara can explain lessons, summarize topics, and answer your study questions — available from the Go plan and above.


Lara helps you learn faster — exclusive to ReadyTools Go, Plus, and Max members.

Track Your Progress 🚀

Learn more easily by tracking your progress completely for free.