Why does Python not support multiline comments

Use comments in Python

Comments in programs can be used for different purposes. These include the typical 3 following variants:

  • explanatory comments within the code
  • better readability of the code
  • to test code or to prevent the execution of commented out program parts

explanatory comments

If a program becomes more complex and you have been in charge of it for years or several people work on the same software, it is helpful to comment on sections of code. Even years later, it is therefore quickly clear why something was implemented in the appropriate way at a certain point.

Comments can also help when programming in teams.

As a beginner, however, you will benefit more from the following types:

better readability of code

The source code can be made more readable through comments. By indenting, Python already forces you to have very clean code. However, depending on the application, a comment can further improve readability.

Comment out to test code

If a part of the program does not work as desired, existing code can be quickly commented out and test code inserted. Code that has been commented out can be reactivated quickly after the error has been found. This has the great advantage over deleting that everything is available again and nothing is accidentally forgotten.

Opportunities for commenting / uncommenting

Comments start with a hash. Everything after the pound "#" is ignored by Python.


The comments can also be placed after commands. From the double cross "#" everything is ignored!

If a code is to be commented out ("switched off"), the pound sign is simply placed at the beginning of the line:

As a result, we only get the word “world” as output. The line with the output for "Hello" is completely ignored by the comment character.

Multi-line comments

Most of the time, you don't want to comment out just one line of code and you don't want to put a pound in front of each individual program line. Then you have the option of commenting out several lines in one fell swoop.

This is done using 3 double quotes:

At the end there are again 3 double quotation marks. From now on all Python commands will be executed again.

This procedure can be used both for placing extensive comments and for commenting out entire program parts:

Recommend • Social Bookmarks • Thank you