How to comment out multiple lines of code in Python?
Hello, I am a newbie in Python for a week. I know to command a line of code we can use
But have some cases I want to comment out multiple lines of code in Python. I try with /**/
/* Hello, I'm a newbie in Python. How can I comment out a block of code? Thanks!!! */ print('Hello, world!')
But it does not work for me. How can I do it?
majid gholipour Aug 01 2021
You can't use /**/ to comment out multiple lines of code. You can replace it with ''' '''. See an example below:
''' Hello, I'm a newbie in Python. How can I comment out a block of code? Thanks!!! ''' print('Hello, world!')
hope it helpful for you.
Developer Aug 01 2021
You can use """ to help comment out a block of code in Python. See an example:
def add_stuff(a, b): result = a + b """ Now we return the result, wee! Hurray! I'm so excited I can't contain my joy to just one or two lines! """ return result number = add_stuff(1, 2) print(number)
It seems so easy!!!
Unnop Niratiam Aug 01 2021
1. In Visual Studio, blocks can be commented out by
Ctrl+K+Cand uncommented by
2. In PyDev (and in Aptana Studio with PyDev):
Ctrl + 4- comment selected block
Ctrl + 5- uncomment a selected block
3. In Eclipse using PyDev, you can select a code block and press
Ctrl + #.
4. On Eric4 there is an easy way: select a block, type
Ctrl+Mto comment the whole block or
5. In JetBrains PyCharm on Mac use
Command + /to comment/uncomment a selected block of code. On Windows, use
CTRL + /.