Views: 20,695
In our previous article, we covered the basics of launching Jupyter Notebook. Now, let’s move on to explore its features and some of the most commonly used keyboard shortcuts.
Types of cells
Jupyter Notebook relies heavily on the concept of cells. The 2 main types of cells are Code and Markdown.
- Code cell: for running code snippets, e.g. python code
- Markdown cell: for displaying formatted text and media assets (learn about Markdown syntax here)
Apart from using the menu bar options, you may also use the following keyboard shortcuts to change the cell type:
Press
Press
Keyboard input modes (Edit / Command)
Jupyter Notebook has 2 keyboard input modes:
Edit mode (cell with green border)
Allow you to type code or text into a cell. You can enter into edit mode by clicking the text area of the selected cell.
Command mode (cell with blue border)
Allow you to perform actions like selecting multiple cells, copying and pasting cells, adding or deleting cells, etc. To perform the above actions, you need to first enter into command mode by pressing
Add/Delete cell
To add new cell, press the “+” button on the menu bar.
For keyboard shortcuts:
(1) Select the target cell
(2) Press
(3) Use the following shortcuts:
- • Press
a : Insert a cell above the selected cell - • Press
b : Insert a cell below the selected cell - • Press
d d : Delete the selected cell(s)
Run cell
Click the “Run” button on the menu bar to run individual cell.
For keyboard shortcuts:
Press
Press
Press
If you would like to run all the cells in the notebook at once, simply go to “Kernel” → “Restart & Run all” on the menu bar.
Shortcuts for the “Run All” action:
1. Press
2. Press
3. Press
You may also create a custom shortcut for this action by going to “Help” → “Edit Keyboard Shortcuts” on the menu bar.
Move cell
You may click the up and down arrow buttons on the menu bar to rearrange the order of the cells.
Shortcuts summary
Below are some commonly used keyboard shortcuts.
You may view all the default shortcuts by going to “Help” → “Keyboard Shortcuts” on the menu bar or by clicking the shortcut
For Mac users, please map your keystrokes as follows:
Shortcuts | Actions |
---|---|
Switch from Edit mode to Command mode | |
Change to Code cell | |
Change to Markdown cell | |
Insert a cell above the selected cell | |
Insert a cell below the selected cell | |
Delete cell | |
Cut cell | |
Copy cell | |
Paste cell below | |
Paste cell above | |
Merge selected cells / If only one cell is selected, merge current cell with cell below | |
Run selected cells | |
Run cell, select below | |
Run cell and insert a cell below | |
Comment | |
Indent | |
Dedent | |
Delete whole line |
Let’s try it out! Increase your efficiency and productivity levels when using Jupyter Notebook.
– By Holly Chan, Library
August 3, 2023