Ask coding questions

← Back to all posts
How to comment out a block of code in Python?
sorenn

How do I comment out a block of code in Python?

Literally everyone I've asked said CTRL + Shift + 7 (CTRL + "/"). I've even it on this website, Reddit and Stackoverflow but it just doesn't work on my end. I've asked several people and no one else has this issue. It's literally three buttons and I've spent hours trying to figure this out and it's driving me insane at this point.

I'm on Chrome - Windows 10.

It's not my keyboard. I've tried my own keyboard, a USB one and the On-screen one in Windows. None of them work.

Help?

Voters
sorenn
Comments
hotnewtop
svensk007

It's simple just do #[your text/code here]
Or you can use
''' [your code/text here for multiple lines] '''

sorenn

@svensk007 That's not even the question, so if you're to tell me that the problem I've been trying to solve for hours is simple, the least you can do is address the problem itself.

svensk007

@sorenn Well then I'm confused about what's wrong now because that is how to make it a "comment" in the code so it doesn't run.

devbois

@sorenn dude that is exactly what(it seems) you asked. maybe you could clarify it a bit further?

sorenn

@BooleanBean @svensk007 I'm asking how to comment out multiple lines (a block) of code at once.

Commenting out one line or creating a string was never the question.

svensk007

@sorenn yeah just use the
' ' '
x = 57
elif x == 57: <--- error here you don't know about
print(x)
' ' '

'''
[line of code]
[line of code]
[line of code]
[line of code]
'''

devbois

@sorenn then just put three 's to start and stop the commenting.

Coder100

hmm

well it won't hurt to just manually comment it out with a multiline string

DynamicSquid

Why doesn't ctrl + / work for you?

sorenn

@DynamicSquid I wish I knew. When I do it, nothing happens.

DynamicSquid

@sorenn Works perfectly for me? Try submitting a bug request.

IntellectualGuy

@DynamicSquid When did you become a mod?

DynamicSquid

@IntellectualGuy 9 hours ago :)

IntellectualGuy

@DynamicSquid Gud, you deserve it

DynamicSquid
Kiploners

@DynamicSquid - on my keyboard it is the /? button

sorenn

I've also tried these: Alt + Shift + A puts what I've marked in '''marked''' but the rest do nothing