Search
A Brief Introduction to Jupyter Notebooks

Jupyter Notebooks combine an execution environment for R/Python/Julia/Haskell with written instructions/documentation/descriptions as markdown. They are organized in cells, and each cell has a type. For use, two types of cells are relevant, Markdown and Code.

Markdown Cells

The Markdown cells contain textual information that is formatted using Markdown. An explanation for how Markdown works can be found as part of the Juypter Documentation. For this exercise, we use the Markdown cells to provide explanations, define tasks, and ask questions.

Code Cells

The code cells contain exectuable code. Each cell is executed on its own and there is no fixed order for the execution. To execute the code in a cell, you simply have to click on the Run button at the top of the page or hit Ctrl+Enter. Code has to be written in R, Python, Julia, or Haskell. All cells within the same notebook must use the same language, which is defined by the kernel of the notebook. We provide the notebooks to you with the Python kernel enabled. You may switch to a different kernel using the menu bar by clicking on Kernel-->Change Kernel and then selecting the language of your choice.

The Internal State

While the cells are executed on their own, they all share the same state. For example, if you load a library in one cell, it will be available in all cells. Similarly, if you store something in a variable, this variable will be globally accessible from all other cells. The state can be reset by restarting the kernel. This usually happens automatically, when you re-open the notebook. You can also trigger this manually using the menu bar by clicking on Kernel-->Restart.

The Output

The output of a code cell appears below the cell. By default, the result of the last executed line is printed. Other textual outputs can be generated by using the print-commands of the programming languange. The generation of plots and similar elements will be covered in this exercise.

Hello World

Below this cell, you find a code cell that contains the code for printing "Hello World" in Python. Execute the cell and see what happens.

print("Hello World")

You actually do not require the print function to achieve the same result, because the return value of the final line is printed automatically. The cell below accomplishes (almost) the same thing, because Jupyter notebook prints the return value of the last executed statement.

"Hello World"