DEV Community

anesmeftah
anesmeftah

Posted on

Python Tip: Quickly Comment or Uncomment Multiple Lines

Tired of typing # on every line in Python? Most editors (VS Code, PyCharm, Jupyter) have a shortcut that makes this instant:

Windows/Linux: Ctrl + /

Mac: Cmd + /

*How it works:
*

  1. Highlight the lines you want to comment or uncomment.

  2. Press the shortcut.

  3. Done! Press again to remove the comments.

x = 10
y = 20
print(x + y)

Highlight and hit Ctrl + / → all lines get commented out in one go. Press again → they’re back!

A tiny shortcut, but a huge time-saver when debugging or experimenting.

Top comments (0)