Comments & Syntax Rules
Learn single-line and multi-line comments, and Python indentation guidelines.
Learning objectives
- Write clean single-line and docstring comments
- Understand the importance of indentation in Python code blocks
Lesson material
Comments in Python
Comments explain what code does without being executed.
- Single-line comments start with
# - Multi-line docstrings use triple quotes
""" ... """
Example code
# This is a single-line comment
print("Code runs!") # Inline comment
"""
This is a multi-line docstring comment.
It can span across multiple lines.
"""
print("Finished!")
Practice exercise: Adding Comments
Fix the code so that "Secret Code" is commented out, and only "Public Code" is printed.
Test yourself with the Module 1: Getting Started with Python quiz →