Comments are part of your code that is for humans not computers. They allow you to make notes about what a line or section of computer code does.
Comments should be helpful and describe algorithms or difficult to understand parts of a program. It is often more useful to comment a section of code than each individual line.
# This is a comment
There is no output as comments are ignored when the program is run.
# Put the comment after a hash symbol
Nothing will happen when this is run. The line of code will be ignored.
radius = 10
area = 3.14 * radius #We don't need an accurate value for pi here
The value 31.4 will be stored in the area variable. The comment after this will be ignored.
# The following algorithm will
# calculate the distance between
# the two points on the map
These three lines would be ignored when the program is run.
'''The following algorithm will
calculate the distance between
the two points on the map'''
Comments are important both for other programmers to understand your code and also for you to understand it. They make it easier for you or someone else to maintain your code. The computer will ignore these comments.
Python multi-line comments should have a # at the start of each line. However, you can start and end a multi-line comment with triple-quotes, like this: '''. These only need to be put at the beginning and end of the section.