Jupyter#

Jupyter aims to provide tools for interactive programming across multiple languages, including the three core languages Julia, Python and R, from which the name is derived. Besides the core languages, there is a long list of other kernels that are available (including Matlab, Fortran, Java)

The Jupyter environment#

Other notable projects that rely on Jupyter are Jupyter Books (to create beautiful, publication-quality books), SoS (for using multiple different kernels in one document)

Why use Jupyter?#

  • Combine Code, Text, Equations and Visualisations

    Jupyter notebooks can be broken up into Code and Markdown blocks. Markdown blocks blocks can include Latex Equations (put between $signs, like $TS=10log_{10} (\sigma_{bs})$ renders as \(TS=10log_{10} (\sigma_{bs})\)). Additionally Markdown blocks can include images, list, tables etc…
    This makes notebooks useful to:

    • Write code documentation (but Notebooks are no replacement for comments or docstrings!)

    • Generate sclear and transparent reports

    • Explain scientific work with equations

  • Data Visualisation and Exploration Jupyter allows the generation of inine plots, integrating well with most standard plotting libraries, including Matplotlib, Seaborn, Plotly, Holoviews, and others. Jupyter also supports the integration of Dash or Bokeh widgets to add even more interactivity.

  • Easy Sharing & Collaboration Jupyter notebooks, use the ipynbending which can be converted to HTML, PDF, Markdown, Python, LaTeX, executable Python script, asciidoc or as Slides. Notebooks can directly be shared through GitHub, Google Colab or Binder and JupyterHub can be used for multi-user collaboration.

What are differences between Jupyter and JupyterLab?#

Feature

Jupyter Notebook

JupyterLab

Interface

Basic

Modern, IDE-like

Multiple Tabs

No

Yes

File Management

Simple

Advanced (drag-drop, side panels)

Customization

Limited

Extensive

Extensibility

Few extensions

Many extensions

Basically JupyterLab is the new, more extensive, powerful and fancy sibbling of Jupyter Notebook. In most cases it makes sense to use JupyterLab.

Installing Jupyter#

The easiest way to get started with the Jupyter environment is to install the full Jupyter package with:

mamba install -c conda-forge jupyter

This will include:

Package

Description

Jupyter Notebook (notebook)

The classic Jupyter Notebook interface

JupyterLab (jupyterlab)

The modern, more powerful Jupyter interface

IPython (ipython)

Interactive Python shell used by Jupyter

Jupyter Client (jupyter_client)

Manages communication between the notebook and kernel

Jupyter Core (jupyter_core)

Core functionalities for Jupyter

Nbconvert (nbconvert)

Converts notebooks to formats like HTML, PDF, Markdown

Nbformat (nbformat)

Handles notebook file formats (.ipynb)

Jupyter Console (jupyter_console)

Command-line interface for Jupyter kernels

QtConsole (qtconsole) Jupyter interface with a Qt-based GUI (optional)

If you only want to use Jupyer Notebook use:

mamba install -c conda-forge notebook

or if you only want JupyterLab:

mamba install -c conda-forge jupyterlab

To run Jupyter notebook, open a Terminal window and browse to the folder within which you want to work. Now run:

jupyter notebook

This will open a browser window with the files in the selected folder.

Notebook Basics#

The first step will be to create a new Notebook:
New Notebook

Now you are ready to write code and Markdown content!

Mode Switching#

Jupyter has two modes:

  • Command Mode (Press Esc) → Used for navigating and managing cells.

  • Edit Mode (Press Enter) → Used for typing inside a cell.

Action

Shortcut Key

Description

Switch to Command Mode

Esc

Exit Edit Mode to navigate cells

Switch to Edit Mode

Enter

Enter Edit Mode to modify a cell

Cell Operations#

Command Mode - Press Esc First

Action

Shortcut Key

Description

Run Cell & Stay

Shift + Enter

Runs the cell & moves to the next one

Run Cell & Insert Below

Alt + Enter

Runs the cell & inserts a new one below

Run Cell & Select Above

Ctrl + Enter

Runs the cell but does not move

Insert New Cell Below

B

Adds a new cell below the current one

Insert New Cell Above

A

Adds a new cell above the current one

Delete a Cell

D D (double press)

Deletes the selected cell

Undo Delete

Z

Restores the last deleted cell

Copy Cell

C

Copies the current cell

Cut Cell

X

Cuts the current cell

Paste Cell Below

V

Pastes the copied/cut cell below

Paste Cell Above

Shift + V

Pastes the copied/cut cell above

Move Cell Up

Shift + Up

Moves the selected cell up

Move Cell Down

Shift + Down

Moves the selected cell down

Change Cell to Code

Y

Converts the cell to a code cell

Change Cell to Markdown

M

Converts the cell to Markdown mode

Merge with Cell Below

Shift + M

Merges the selected cell with the one below

Text Editing Shortcuts#

Edit Mode - Press Enter First

Action

Shortcut Key

Description

Autocomplete Code

Tab

Auto-suggests methods/variables

Show Documentation

Shift + Tab

Shows docstring/help for a function

Comment/Uncomment Line

Ctrl + /

Toggles comments for selected lines

Indent Code

Tab

Indents selected code

Unindent Code

Shift + Tab

Unindents selected code

Kernel & Execution#

Action

Shortcut Key

Description

Interrupt Kernel

I I (double press)

Stops the current execution

Restart Kernel

0 0 (double press)

Restarts the notebook kernel

Restart & Run All Cells

Ctrl + Alt + R

Restarts kernel & runs all cells

Notebook Navigation#

Action

Shortcut Key

Description

Toggle Sidebar

Shift + Space

Shows/hides the sidebar

Go to Next Cell

Down Arrow

Moves to the cell below

Go to Previous Cell

Up Arrow

Moves to the cell above

Open Command Palette

Ctrl + Shift + C

Opens the Jupyter command menu

Show Table Of Contents

Ctrl + Shift + K

Shows / hides the TOC

How to See All Shortcuts in Jupyter Notebook?#

Press:

  • Ctrl + Shift + H (in Command Mode) → Opens a help window with all shortcuts

  • Ctrl + Shift + P → Opens the command palette for searching commands

Tip

You can customize shortcuts in Help > Edit Keyboard Shortcuts.

Basic Markdown Skills#

Category

Syntax

Example

Rendered Output

Headings

# Heading 1
## Heading 2
### Heading 3

## This is a subheading

This is a subheading

Bold Text

**bold** or __bold__

**Important**

Important

Italic Text

*italic* or _italic_

*Emphasized*

Emphasized

Bold + Italic

***bold & italic***

***Very important!***

Very important!

Strikethrough

~~strikethrough~~

~~wrong text~~

~~wrong text~~

Lists

- Item 1
- Item 2

- Apple
- Orange

- Apple
- Orange

Ordered List

1. First item
2. Second item

1. Start
2. Continue

1. Start
2. Continue

Inline Code

`code`

`print("Hello")`

print("Hello")

Code Block

```python
print(“Hello”)
```

python print("Hello")

Python code block

Blockquote

> This is a quote

> Jupyter is great!

> Jupyter is great!

Horizontal Line

--- or ***

---

Hyperlink

[text](URL)

[Google](https://google.com)

Google

Image

![alt text](image_url)

![Jupyter Logo](https://jupyter.org/assets/nav_logo.svg)

Jupyter Logo

LaTeX Math

$E=mc^2$

$E=mc^2$

(E=mc^2)

—-
Alice

25

Task List

- [ ] Task 1
- [x] Task 2

- [ ] To do
- [x] Done

☐ To do
☑ Done

Tables:

|Name     |Language |Age  |
|---------|---------|-----|
|Kim      |Python   |42   |
|Sascha   |R        |24   |

will render as:

Name

Language

Age

Kim

Python

42

Sascha

R

24