Comments in Python
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
Wir haben die Materialien überprüft, dennoch können Fehler vorkommen. Der Inhalt dient ausschließlich Bildungszwecken, daher verwende ihn auf eigene Verantwortung und überprüfe ihn bei Bedarf mit anderen Quellen.
✨ Frag Lara — deine KI-Lernpartnerin
Entsperre personalisierte Lernunterstützung. Lara kann Lektionen erklären, Themen zusammenfassen und deine Lernfragen beantworten — verfügbar ab dem Go-Tarif.
Lara hilft dir, schneller zu lernen — exklusiv für ReadyTools Go-, Plus- und Max-Mitglieder.

