To use this website fully, you first need to accept the use of cookies. By agreeing to the use of cookies you consent to the use of functional cookies. For more information read this page.

Part 2.2Comments in Python

Commenting is a very useful way of reminding future programmers or the original programmer when they haven't programmed on the same project for a long time what a section of code does. Therefore, it is recommend to comment code while working on it.

Most commercially developed applications have been commented because a wide array of people will work on them.

Commenting code in Python

There are two methods of commenting in Python. The first is the single line comment. This comment will take just that line of code out of the interpreted program. This is achieved using the # hash sign in Python:

Python
#This is a comment


The second option is the block comment (also known as a multi line comment). This will remove multiple lines of text from the interpreted program. This is achieved using the ''' syntax:

Python
'''This is a comment
This is also a comment
'''

Code preview
Feedback 👍
Comments are sent via email to me.