Shortcut key remove or add #comments in python?


# # Reproduce the Bug
# from random import randint
# dice_imgs = ["❶", "❷", "❸", "❹", "❺", "❻"]
# dice_num = randint(0, 5)
# print(dice_imgs[dice_num])}

how to remove # beginning of codes just in a using shortcut key? Please help. Thanks.

It should not automatically comment. Mabey try deleting the # then write code and see if the following lines become comments since I cant repro this.


Hi @dnrts good question.

I’d use search and replace (usually CTRL+H) to search for # and replace it with an empty field.


Hi @dnrts another option is to use the Toggle Line Comment Shortcut Key to toggle comment on/off for the current line or selection. (on windows use CTRL+/, or on macOS use CMD+/)

1 Like

ctrl+/ will comment. I found it by accident a couple days ago when programming in java, and I checked in python and it comments with # just the same. Will also work with multiline #s


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.