How to write Comments in Python3?

Published on Aug. 22, 2023, 12:15 p.m.

In Python, you can write single-line comments using the hash symbol #. Any code after the # symbol on that line will be ignored by the Python interpreter. For example:

# This is a single-line comment in Python

To write multiline comments in Python, you can use either a multiline string enclosed within triple quotes ''' or """ or use multiple single-line comments. The former is more commonly used for documentation purposes. Here’s an example:

'''
This is a multiline comment in Python
It can span across multiple lines
'''

or

# This is a multiline comment
# in Python using multiple single-line comments
# It can span across multiple lines

It’s important to note that while you can write long multiline comments, PEP 8 (the Python style guide) suggests limiting line length to 72 characters for inline comments and docstrings.

Tags: