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
Hemos revisado y comprobado los materiales, pero aún pueden existir errores. El contenido se ofrece únicamente con fines educativos, así que úsalo bajo tu propia responsabilidad y verifica con otras fuentes si es necesario.
✨ Pregunta a Lara — tu compañera de estudio con IA
Desbloquea soporte de aprendizaje personalizado. Lara puede explicar lecciones, resumir temas y responder tus preguntas — disponible desde el plan Go y superiores.
Lara te ayuda a aprender más rápido — exclusivo para los miembros ReadyTools Go, Plus y Max.
