Jupyter Notebook Cheat Sheet

In Jupyter

Jupyter Notebook is an open-source web application that allows users to create and share documents that contain live code, equations, visualizations, and narrative text. It is widely used in data science, scientific computing, and machine learning.

Jupyter Notebook supports over 40 programming languages, including Python, R, Julia, and Scala. It provides an interactive environment for data exploration, analysis, and visualization. Users can write and execute code, view and manipulate data, and create visualizations all in one place.

This cheat sheet provides an overview of the most commonly used Jupyter Notebook commands and shortcuts.

Table of Contents

Keyboard Shortcuts

ShortcutDescription
EscEnter command mode
EnterEnter edit mode
Shift + EnterRun cell and select next cell
Ctrl + EnterRun cell
Alt + EnterRun cell and insert new cell below
YChange cell type to code
MChange cell type to markdown
AInsert cell above
BInsert cell below
D, DDelete selected cell
ZUndo cell deletion
Shift + MMerge selected cells
Ctrl + SSave notebook
Shift + LToggle line numbers
Shift + TabShow docstring for object
Ctrl + Shift + -Split cell at cursor
Ctrl + Shift + POpen command palette

Cell Operations

OperationSyntaxDescription
Comment#Add a comment to a code cell
Outputprint()Display output from a code cell
Clear OutputCtrl + LClear the output of a cell
InterruptI, IInterrupt the execution of a cell
Restart0, 0Restart the kernel
Run AllShift + R, ARun all cells in the notebook
Run SelectedShift + R, SRun selected cells in the notebook

Markdown Formatting

SyntaxDescription
#Heading
**bold**Bold
_italic_Italic
---Horizontal line
* itemUnordered list
1. itemOrdered list
> quoteBlockquote
![alt text](image.png)Image
[link text](http://url.com)Link

Magic Commands

CommandSyntaxDescription
List%lsmagicList all available magic commands
Time%%timeTime the execution of a cell
Load%load file.pyLoad code from a file into a cell
Save%save file.pySave code from a cell to a file
Debug%debugEnter interactive debugger
PDB%pdbAutomatically enter debugger on error
Matplotlib%matplotlib inlineDisplay matplotlib plots inline

Debugging

CommandSyntaxDescription
Set Breakpointimport pdb; pdb.set_trace()Set a breakpoint in code
NextnExecute the current line and move to the next line
StepsStep into a function call
ReturnrContinue execution until the current function returns
QuitqQuit the debugger

References