Python Mastery – From Basics to Brilliance / Python Fundamentals

Comments & Docstrings

Comments are non-executed lines of code used to describe what the code is doing. They help others (and future you!) understand the code.

🧾 Single-line Comment:

# This is a comment
name = "John"  # variable to store name

🧾 Multi-line Comments:

# This is a
# multi-line comment

📘 Docstrings:

Docstrings are used to describe what a function, class, or module does.

def greet():
    """
    This function prints a greeting message.
    """
    print("Hello!")

Use help(greet) to see the docstring.

💡 Real-life Example:

Think of comments like sticky notes on a recipe: they don’t affect the recipe but help you understand the steps.