user
How to comment several lines in Jupyter Notebook
alphonsio

In Jupyter Notebook (or JupyterLab), you can comment/uncomment multiple lines at once using a keyboard shortcut:

  • Windows/Linux → Select the lines you want to comment, then press
    Ctrl + /

  • Mac → Select the lines you want to comment, then press
    Cmd + /

This will toggle comments:

  • If the lines are not commented, it will add a # at the beginning of each selected line.
  • If they are already commented, it will remove the #.

Alternative: You can also manually add # at the start of each line, but the shortcut is much faster.