How do you comment out code in Python using multi-line comment?

Experience Level: Junior
Tags: Python

Answer

Python doesn't support multi-line comments.

The workaround is to prepend each line in the block that you want to comment out with the hash (#) character.

Example:

# This block of the code
# is commented out
# and it is not executed by Python.
print("and this is executed")

Python for beginners
Python for beginners

Are you learning Python ? Try our test we designed to help you progress faster.

Test yourself