How to comment out a block of code in Python
In Python, you can comment out a block of code by using the "#" symbol at the beginning of each line. For example:
# This is a comment
# print("This line of code will not be executed")
print("This is the main code and will be executed")
Watch a video course
Python - The Practical Guide
Another way to comment out multiple lines of code at once is to use triple quotes """
. This can be used for both single or multiple line comments.
"""
This is a multi-line
comment that can span multiple lines
"""
print("This is the main code")
Alternatively, you can also use the '''
for multiple line comments.
'''
This is a multi-line
comment that can span multiple lines
'''
print("This is the main code")
Please note that, comments have no effect on the execution of code, they are only for human readers to understand the code.