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
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.
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
- How do I find my falsetto
- Malaysia Airlines is going downhill
- Why does mainland China not have free internet
- Using smartphones can cause finger pain
- What are slow classical music
- What is the full form of MPS
- What is the purpose of adiabatic cooling
- What don't people tell you about dropshipping
- What is the theory of interpreting
- Solar energy would work in Karachi Pakistan
- Manchester is blue now
- How do you wish you look
- What is the lowest quality Marvel movie
- How does AI affect advice?
- Is intelligence a good quality?
- With whom does Celaena end
- How can I overcome being emotionally unavailable
- Can you freeze cantaloupe
- What is a low level web service
- Can you tell us something about project solos?
- When do the ATMs roll over?
- How much does a battery cost
- Are social networks more useful than harmful
- Can we register the partnership registration online