Home »
Python
How do we create multiline comments in Python?
Last Updated : April 20, 2025
When we need to comment on multiple lines/statements, there are two ways to do this, either comment each line or create multiline comments (or block comment).
In C / C++, we use /*...*/ for the multiline comment, but in Python programming language, we have two ways to comment a section.
Python - Multiline Comments
The first way is to comment on each line,
This way can be considered as a single line comment in Python – we use the hash character (#) at the starting of each line to be commented.
# This is line 1
# This is line 2
# This is line 3
And, the second way is to comment the section,
This way can be considered as a multiline comment in Python – we use triple single quotes (''') at the starting of the section to be commented and again triple single quotes (''') at the end of the second.
'''
This is line 1
This is line 2
This is line 3
'''
A Python example for creating multiline comment
'''
Function name: print_text
Parameters: None
Return type: None
Description: This function will print
some text on the screen
'''
def print_text():
print("Hello, world! How are you?")
if __name__ == "__main__":
# Here, we will call the print_text function
# that will print some text on the screen
print_text()
Output
Hello, world! How are you?
In the above program, there are two multiline sections which we is commented,
Section 1:
'''
Function name: print_text
Parameters: None
Return type: None
Description: This function will print
some text on the screen
'''
Section 2:
# Here, we will call the print_text function
# that will print some text on the screen
Python Multi-line Comments Exercise
Select the correct option to complete each statement about multi-line comments in Python.
- Python does not have a dedicated syntax for multi-line comments, but we can use ___ to achieve the effect.
- A common alternative for multi-line comments in Python is using ___.
- Triple-quoted strings are only treated as comments when they are ___.
Advertisement
Advertisement