Program comments are a part of the program that is not executed and are not visible to the user.
They are used to explain what the code does, either to someone else or your future self.
In Python, line comments start with #. It can be placed on a line of it's own or at the end of a line of code.
Docstrings are a type of multi-line comment using """"""
Examples:
Full line Comments:
# Set first variable
firstName = "Craig"
# Set second variable
lastName = "Smith"
# Combine the variables
fullName = firstName + " " + lastName
# Print the combined variable
print(fullName)
End-of-Line Comments:
firstName = "Craig" # Set first variable
lastName = "Smith" # Set second variable
fullName = firstName + " " + lastName # Combine the variables
print(fullName) # Print the combined variable
Docstring:
"""
This is a test of
The Emergency Broadcast System (EBS)
This is only a test
"""
A programmer I work with once told me "You should have nearly as many comments as lines of code"