Categories
Python Programming

Comments

When writing code in the Python programming language, you use comments to isolate portions of the program that you don’t want the interpreter to run.

Comments are used to:

  • Document a program
  • Isolate a portion of a program during debugging
  • Make code more understandable to the programmer

Creating a Comment

To create a comment in the Python programming language, the # symbol is used.

# can be used above a line of code or inline.

#This is a comment
print("Hello, World!")

print("Hello, World!") #This is a comment

Multiline Comments

In the Python programming language, multiline comments don’t exists. However, you can use the docstring which are made using the “”””””.

"""
This is a comment
written in
more than just one line
"""
print("Hello, World!")

The docstring is specifically meant for documenting a method or function in the Python programming langauge.

Conclusion

Comments are used in programming languages to document, debug and make code understandable. They can be single line comments or multiline comments.

Leave a Reply

Your email address will not be published. Required fields are marked *