Python Comments – Adding multiline comments to code

Comments can be used in a few ways, the first of which is to explain your code, this can be invaluable to any one who may be reading your code. They are also useful in testing, whereby parts of code can be turned in to comments to stop them from being executed.

Whilst it is favoured to use consecutive single line comments via the ‘#’ hash character, multiline comments are still possible via the use of triple-quoted strings as seen below.

This is 
a multiline

print("Hello World!")

The triple-quoted strings would need to be present both before and after the comment itself.

Leave a Reply