Question:
Python language: Is there a way to comment out a block of code?
MavistheMaven
2012-08-08 08:19:19 UTC
I don't want to have to put a "#" in front of every line of code I want to comment out. Is there a way, in Python, to comment out a multi-line block of code?

Thanks!
Four answers:
Qwen
2012-08-08 08:35:52 UTC
Highlight the code you want to comment out, and choose from the menu of the editor the option to comment it out. It is not installed in this computer, so I can't check the shortcut or the place to click.



Also this works:



#if 0

code

#endif



So here the "code" is commented out.
radicalbiscuit
2012-08-08 09:00:33 UTC
The common method is to use literal quotes above and below the block you want to comment out. Because string literals can span multiple lines, you don't have to comment out each line individually.



Example:



"""

here is the code you want to comment out

and it goes on

for several lines

"""



Python will just pass over it, considering it a string object with no actions attached to it. Please note you can also use the single-quote literals.



'''

here is the code you want to comment out

and it goes on

for several lines

'''



This is helpful if you, for some reason, have a literal quote inside the code block you're commenting out. You just use the other type of literal quote, different from the type you use in your code.
?
2017-01-15 19:14:08 UTC
C++ is the main appreciably used programming language, so this is totally functional to be responsive to it. it is not complicated to learn. traditionally, difficulty-unfastened has been taught as a conventional language, because of fact the call implies, even though it is not appreciably used at the instant, so this is of little functional value as quickly as you have discovered it. there are a number of different languages you may desire to learn: APL, Algol, Ada, Fortran, COBOL, Java, Javascript, own living house page, Perl, Python, PL/I, RPG, you call it. Be cautioned that programming is like composing music: all and sundry can discover ways to do it, yet oftentimes basically those with a organic knack for it substitute into quite stable at it. of path, in case you basically desire to characteristic it on your resume, you do no longer unavoidably would desire to be stable at it (yet nonetheless, while you're no longer stable at it, it does not serve lots purpose first of all). The cplusplus website is tremendously stable for reference. in spite of if or no longer the tutorials are stable relies upon lots on your character and getting to grasp style. i've got on no account used tutorials for any languageā€”I basically study the reference cloth and start up coding. yet some human beings do desire to be led by way of recent techniques till now they attempt something on their very own.
James
2012-08-08 09:57:31 UTC
"""

code

"""

or

idle only

select the code

format>comment out region


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...