Comments in Python Code

The "#" starts a comment which tells Python to ignore everything after the # on that line. The "#" can be at the start of a line or after some code.

Examples

Python
# These are comment lines. You use these to explain the purpose
# of the next block of code
Python
print('Hello World!') # A comment after some code.

Notes

This code:

Python
# print('Hello World!')

comments out the code line and therefore it will not execute.

Comments should explain why the code is doing something, rarely what the code is doing, as the what can be gleaned from the code.

Don't add comments that are obvious:

Python
print(name) # Print the name

Instead, use comment to explain something that may not be obvious, or explain why you've chosen a certain approach

Python
for x in range(10, 1):        # Starting from the end is actually faster.
    if element_must_be_removed(i):
        remove_element(i)