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 ignoredQuiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.