This Python Comments lesson is for a beginner. Read the short notes, run each example, then change one name or number and run it again.
A comment starts with # and runs to the end of the line. Python ignores it. Write comments for the reason, not for what the next line already says.
A triple-quoted string under a function name is a docstring. Help tools can read it.
Example 1: Start here
Comments are for people. They do not change the result.
# fee is a planning figure, not a quote
fee = 25000 # a whole number
print(fee) # show the number
Example 2: Ignore a note
Python skips the words after #. The number is still printed.
fee = 25000 # planning figure, not a quote
print(fee)
Example 3: Comment a whole line
A line that starts with # does nothing.
# this line is not code
print("only this line runs") # print writes this; the quotes are not shown
Example 4: Add a docstring
The triple-quoted line is a docstring. The function still returns the number.
def fee_note(): # define the function; it runs when you call it
"""Explain the fee in one sentence."""
return 25000 # send this value back to the caller
print(fee_note())
