Comments

Comments are lines of code that are ignored by Python.

Comments help the human programmers read a program.

Comments start with #.

# This is a comment
print('not a comment')

Comments are handy for helping your future self remember the code you wrote in the past. It also helps other programmers understand your code in case they take over one of your projects.

“Comment Out” a chunk of code

Another use of comments is for turning certain sections of code on and off. You can “comment out” a section of code by adding # to the start of the lines you want to turn off.

print('Coding is fun')
# print('fishes eats chickens')

This program only prints the first line. The second line is ignored, even though it’s a legal Python command apart from the #.

If you want to bring commented code back in, simply delete the # characters.  This way you don’t lose a section of code and end up rewriting it later.

Block Comments

If you have multiple lines of comments, you can use block comments. Use three quotes in a row at the start and end of the comment block.

print('Hello Program.')
'''
This program has block comments.
The comments span multiple lines.
Three quotes start/end block comments.
'''
print("End of Program.")

Handy Shortcut: control + slash

Many programs use control + slash  as a keyboard shortcut for comments. (This is because the C family of languages uses slashes for commenting) Highlight one or multiple lines of text and push control + slash, and it will add # to the start of each highlighted line.

You can also use that shortcut to remove comments. Highlight one or more lines that already begin with #, then hit control+slash. The # characters will be removed.