Sign in

Everything you need to know about comments in Python

Comments are descriptions that are usually written while coding to enhance the readability and to better understand the functionality of the program. They are ignored by the interpreter while running the code.

PC: Pixabay

Significance of commenting:

  • When reading or editing your own code, after a couple of months, it can be difficult to comprehend the program and can consume hours to understand what’s what! Writing comments while coding is an essential way to prevent this confusion from happening.

Ways to write comments in Python:

Single line comments in Python are written using the hash symbol (#).

For example:

#printing hello world

print(“Hello World”)

2. Multi line comments:

Multi-line comments in Python can be written using the following two ways:

  • By using multiple hash symbols at the beginning of each line of comment

For example:

#this comment is an

#example of multi-line comment

  • By enclosing the comment inside a set of triple quotes

For example:


This is another example of

multi-line comment

to print hello world!


print(‘Hello World’)

Best Commenting Practices:

2. While making changes to any function or any other parts of the code written previously.

3. Make the comments as concise as possible.

4. Avoid writing rude comments as it could offend a team member.

5. Remove redundant comments.