Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
2 views
in Python by (47.6k points)

Is there a mechanism to comment out large blocks of Python code?

Right now, the only way I can see of commenting out code is to either start every line with a #, or to enclose the code in triple quotes: """.

The problem with these is that inserting # before every line is cumbersome and """ makes the string I want to use as a comment show up in generated documentation.

2 Answers

0 votes
by (106k points)
edited by

In Python, we do not have such a mechanism. For commenting single line we use a # to each line. For more information see PEP 8. Most of the Python IDEs support a mechanism for block-commenting-with-pound-signs automatically for you. For example, in IDLE on my machine, it's Alt+3 and Alt+4.

To know more about this you can have a look at the following video tutorial:-

0 votes
by (32.3k points)

You can use the triple quotes for commenting out a block of code:-

''' 

...statements…

''' 

Related questions

0 votes
1 answer
0 votes
4 answers
0 votes
1 answer
asked Feb 9, 2021 in Python by Rekha (2.2k points)
0 votes
1 answer

Browse Categories

...