Skip to content

2.3. Comments

When writing a complex program, your code will surely get complicated at some point. A code is read much more often than it is written. Hence it is important that you ensure that others can understand your code.

This is when comments are helpful. As the name suggests, comments are simply line of codes which solely exist to explain your code. These lines are ignored at execution time. In order to write a comment, start a line by a # symbol.

For example,

# This is a comment
print('This is a normal line of code')

In this code, the first line is a comment which will be ignored during execution.

Uses of Comments

  • Explaining Code: Comments are used to include useful information in code which will help others reading your code. It is a good practice to add comments when you think your code could be too complicated to comprehend by a human.

  • Debugging & Testing: When working with programs, especially investigating errors or bugs in code, it is a common practice to use comments to temporarily prevent a piece of code to execute by commenting out that bit of code.

  • Code Analysis & Type Checking: For some third party tools that perform analysis on code or read the code, comments are used to manipulate their behaviour.


As you'll notice in next articles, we'll use comments throughout this guide for explaining the code snippets included in articles and we hope you do to in your code.