Comments

3.1.3. Comments#

Programs with only a few lines of code are generally easy to understand. As they grow in complexity, we need to document them, usually with comments.

Any text that follows # corresponds to a comment, and it is not executed by Python. Usually, we use comments to explain what is the objective of a section of code.

These codes are completely equivalent:

Without comments

print("Here is a calculation")
print(10 + 5)
Here is a calculation
15

With comments

# Demonstrate comments

print("Here is a calculation")  # Print some text
print(10 + 5)  # Print the result of an addition
Here is a calculation
15