How to use Jupyter Notebook

Summary: in this tutorial, you’ll learn about the interface of Jupyter Notebook and compose a simple document with its cells.

Open Jupyter Notebook

In order to open a Jupyter Notebook, you have to run jupyter notebook from a terminal.

On Linux and macOS, you have a dedicated terminal installed by default. On Windows, the equivalent of a terminal is the Command Prompt.

Running jupyter notebook will start the Jupyter Notebook server at port 8888 and open its web-based interface with your default browser.

If for some reasons the browser doesn’t open on its own, you need to copy the URL from the terminal and access it manually.

Create a new Jupyter Notebook document

In the newly-opened web interface, browse to where you want to place the new Jupyter Notebook and select New > Python 3 from the menu.

A new web editor tab will be opened, allowing you to compose your first Jupyter Notebook. The interface somehow resemblances Google Docs.

Naming Jupyter Notebook document

The first thing you have to do is give the document a name. To do that, click Untitled in the upper area and a Rename Notebook will pops up, allowing you to rename the file.

Our actual document is saved with the .ipynb extension (short for Interactive Python Notebook).

Jupyter Notebook cells

A Jupyter Notebook document consist of multiple “cells”. There are 3 types of cell: text (written in Markdown), code (executable, written in Python 3) and output of the code (after it is evaluated).

Each cell is represented by a rectangular area in the interface.

The innermost text area is where you enter code. Below that, the results of each code stop will be displayed.

Insert a cell

You have several ways to insert a Jupyter Notebook cell.

  • Select Insert > Insert Cell Above or Insert > Insert Cell Below.
  • Click the plus button in the toolbar.
  • Press the A or B key to insert a cell above or below your current position. You had to be out of the code area, otherwise the key won’t be recognized as a quick shortcut.

The new cell will be a Code cell by default. If you want to change it into a Text one, select Markdown from drop-down menu in the toolbar.

Convert a cell from code to markdown

Remove a cell

Similarly, you have two ways to delete the cells you no longer need.

  • Select Edit > Delete Cells from the menu.
  • Select cells and press D key two times.

You can also select multiple cells and delete them all by either pressing Shift + J or hold Shift and click in the blank area of another cell. Please note that this way, you can only delete adjacent cells.

Run a cell

With a code cell, you can run it against the Python 3 interpreter by clicking the Run icon in the toolbar or select Cell > Run cells (hotkey Ctrl + Enter).

After running, the results will be displayed on the bottom of the cell.

If you want to wipe out all the outputs you ran previously to make ways for a total new run, you can do so by selecting Cell > All Output > Clear.

Each code result will be run against the interpreter, variables are stored in the memory. In the example below, I run a cell at the bottom of the document before running the middle one, so the result of the first one can be used.

Summary: 

  • Jupyter Notebook document consist of text cells, code cells and output cells.
  • Jupyter Notebook document is saved to disk with the extension .ipynb.
  • Code cells inside a Jupyter Notebook can be ran against the Python interpreter.

Leave a Comment