W3docs

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.

In Python, you can comment out a block of code by using the "#" symbol at the beginning of each line. For example:

An example for commenting out single code lines in Python

python— editable, runs on the server

<div class="alert alert-info flex not-prose"> Watch a course <span class="hidden md:block">Watch a video course </span> Python - The Practical Guide</div>

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.

An example for commenting out multt-line code in Python with three double quotations

python— editable, runs on the server

Alternatively, you can also use the ''' for multiple line comments.

An example for commenting out multt-line code in Python with three single quotations

python— editable, runs on the server

Please note that, comments have no effect on the execution of code, they are only for human readers to understand the code.