Python | Code comments

Comments are ignored by the interpreter. A piece of code will be ignored if it is marked as a comment.

Comments are important, nobody can deny that. Developers use comments in their code as a way of documenting their work, their thoughts about the commented code. When you look at your code’s comments you can remember clearly what were your thoughts at the moment of writing the code.

Comments are used as a team collaboration tool. Comments can served as messages to the people maintaining the code or those who have to continue your work, write code related to your code.

In Python, a single line comment is written using a hash (#). Python interpreter considers a comment everything is after the hash and it is on the same line (single line comment).

print('hello there!')
# Comment
# This is another comment

Python comments

For multi-line comments Python style guide recommends using consecutive single line comments. My advice is to use the hash at the beginning of every single line that is a comment.

Leave a Reply