Skip to content
Justice Tech School

Comments

A comment starts with # and runs to the end of the line. Use comments to explain why code does something. A string in triple quotes at the start of a function or file is a docstring, which documents it.

Example
# This is a comment
print("Hello")  # a comment after code

def area(w, h):
    """Return the area of a rectangle."""
    return w * h

print(area(3, 4))
print(area.__doc__)

Result

Hello
12
Return the area of a rectangle.

Exercise

Which symbol starts a comment?

 this is ignored

Quiz Test

What does Python do with a comment?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.