In the Introduction to Python we worked with the python
interpreter or in ipython
. Our in- and output was completely text based. Furthermore, we could either run a program that we wrote in our editor or we could use the REPL in the interpreter, which provides a very linear and sequential means to execute code.
For interactive data exploration and developing smaller projects it can be very convenient to combine text, code, and graphical output in one document. Such a document is often called a notebook.
In Python, the Jupyter project (which was born from ipython) provides a browser-based notebook environment. Currently two interfaces are available, the “classic” notebook and the modern JupyterLab. You can use either one but in the following we will use the traditional (and simpler) notebook.
Table of contents
Classic Jupyter notebook
Launch the classic Jupyter notebook interface in your web browser1:
How to use the notebook
Basic Jupyter notebook commands:
- Look at the Help menu! (see also the Jupyter Notebook Online Help)
- A notebook has two modes
- edit mode:
- green box around a cell: you can type into the cell
- enter edit mode by pressing
Enter
(orReturn
) or click on a cell
- command mode:
- gray box around a cell (you cannot type into a cell!)
- keys perform many different actions (don’t type randomly…), e.g., cursor keys move up/down,
c
copies a cell,shift + enter
evaluates a cell. - enter command mode by pressing
ESC
or clicking outside a cell’s area
- edit mode:
- Evaluate a cell: in command mode (gray cells with blue side bar):
shift + return
- Change a cell type: menu (code is Python, Markdown is text in Markdown format)
Resources
Footnotes
If you have problems launching the notebook interface on Mac OS X, try
jupyter notebook --ip=127.0.0.1
If problems persist, search the internet for the error message and ask for help. ↩