How do I comment out multiple lines in Jupyter Ipy

2019-01-16 02:14发布

I want to comment out a block of multiple lines in Jupyter (Ipython Notebook), but can't find out how to do that in this current version.
It used to be in one of the drop down menus but is no longer there.
How do you comment out multi-line blocks of code at once?

This is not a duplicate because the solution given in the following link doesn't seem to work anymore:
How can I block comment code in the IPython notebook?

Ctrl + / does nothing.

18条回答
等我变得足够好
2楼-- · 2019-01-16 03:03

Another thing to add, in the version I'm using, the code has to be initialized in order to be to comment it out using CTRL and / . If you haven't ran the code and the code isn't colorized it wont work.

查看更多
爷的心禁止访问
3楼-- · 2019-01-16 03:04

Quick Addition to Top Answer: CTRL + / is nice because it toggles back and forth between adding and removing # at beginning of all selected lines. Didn't see that exact nuance mentioned so just wanted to add it here. (This worked in Firefox Developer Edition 54.0b12 on Windows 7).

查看更多
Ridiculous、
4楼-- · 2019-01-16 03:06

Select the lines on windows jupyter notebook and then hit Ctrl+#.

查看更多
甜甜的少女心
5楼-- · 2019-01-16 03:07

On a Finnish keyboard use Ctrl + ' to comment on multiple lines and use the same keys to de-comment.

Ubuntu 14.04 Google Chrome

查看更多
女痞
6楼-- · 2019-01-16 03:07

TL;DR:

Using MacBook Pro with Spanish - ISO Keyboard.

Solution: Ctrl + -

Full story

This is an old post but reading it got me thinking about possible shortcuts.

My keyboard is a Latin Apple MacBook Pro, which is called Spanish - ISO. I tried the changing keyboard distribution to U.S. solution... this works but with this solution I have to switch keyboards every time I want to comment which... sucks.

So I tried ctrl + - and it works. The - is where the / is located in an english keyboard but doing Cmd + - only changes the Chrome's zoom so I tried Ctrl which isn't as used as Cmd in macOS.

My takeaway with this would be: if I have more shortcut problems I might try the original shortcut but using the key where the U.S. keyboard would have it.

查看更多
家丑人穷心不美
7楼-- · 2019-01-16 03:09

Select the lines you want to comment out. Then press:

Ctrl + #

查看更多
登录 后发表回答