Skip to content
Sign UpLog In
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
2

How to comment out a block of code in Python?

sorenn
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?

2 years ago

Voters

Comments

TopNew
1
DavidJohn9
DavidJohn9

Your article is very good and very informative. I always follow your posts. You are an author that I love. Thank you for sharing! Let's continue to thrive! moviedle

5 months ago
1
andon50
andon50

@sorenn
I have the samt problem, and have as you I think a swedish keyboard. If i change to US keyboard in windows, I can use ctrl + (the minus and underscore key).
Weird!

1 year ago
1
svensk007
svensk007

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

2 years ago
2
sorenn
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.

2 years ago
1
svensk007
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.

2 years ago
1

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

2 years ago
1
sorenn
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.

2 years ago
1
svensk007
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]
'''

2 years ago
1

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

2 years ago
1
Coder100
Coder100

hmm

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

''' def ohno(): print("eeeeee") '''
2 years ago
1
DynamicSquid
DynamicSquid

Why doesn't ctrl + / work for you?

2 years ago
1
sorenn
sorenn

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

2 years ago
1
DynamicSquid
DynamicSquid

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

2 years ago
1
IntellectualGuy
IntellectualGuy

@DynamicSquid
When did you become a mod?

2 years ago
1
Kiploners
Kiploners

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

1 year ago
1
sorenn
sorenn

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

2 years ago
Load more