How do I block comment in Jupyter notebook?
Ctrl + / works for me in Chrome browser in MS Windows. On a Mac, use Cmd + / (thanks Anton K).
Please note, if /
did not work out of the box, try pressing the /
key on the Numpad. Credit: @DreamFlasher in comments to this question.
How can I block comment code in the IPython notebook?
Default solution
In IPython 2.x and 3.x (cmd|ctrl)-/
works but requires an english (american) keyboard layout, see https://github.com/ipython/ipython/pull/3673.
Other keyboard layouts
In case you have a non-english keyboard layout, you can define a custom keybinding for the codemirror editor via your custom.js. To this end add e.g. the following lines
define([
'base/js/namespace',
'base/js/events'
],
function(IPython, events) {
events.on("app_initialized.NotebookApp",
function () {
IPython.Cell.options_default.cm_config.extraKeys = {"Ctrl-," : "toggleComment"};
}
);
}
);
to use Ctrl+, to toggle (block) comments. I use this with a german keyboard layout and IPython 3.0.
The previous solution (see edits) worked fine with chrome, but not with firefox.
Old solution (IPython 1.x)
If you are using IPython 1.x you can try the comment-uncomment.js
from https://github.com/ipython-contrib/IPython-notebook-extensions - I haven't tried this yet, but I guess its a good start.
Commenting multiple lines in an ipython cell
You can use triple-quoted strings. Although this prints a repeats out statement, which I would like to avoid.
'''
This is a multiline
comment.
'''
Jupyter notebook shortcut to uncomment
CTRL+/ is a toggle for comment and uncomment! Thanks George for the answer...
shortcuts for editing code indentation in jupyter notebook
Ctrl-] : indent
Ctrl-[ : shifting back indentation
if it doesn't work, then try:
Tab : indent
Shift + Tab : shfting back indentation
Related Topics
Join Dataframes Based on Partial String-Match Between Columns
How to Convert Column With String Type to Int Form in Pyspark Data Frame
How to Print Superscript in Python
Pythonic Way to Check If Two Dictionaries Have the Identical Set of Keys
How to Change a Two Dimensional Array to One Dimensional
How to Check the Date Is Empty Using Python
How to Remove Comma and Brackets
Add Missing Dates to Pandas Dataframe
How to Print the Even-Indexed and Odd-Indexed Characters of Strings
How to Locate the Index With in a Nested List Python
Overlay a Smaller Image on a Larger Image Python Opencv
How to Get the Name of an Object
Python: How to Calculate the Sum of Numbers from a File
Google Chrome Closes Immediately After Being Launched With Selenium
How to Save Opened Page as Pdf in Selenium (Python)