Contents

Jupyter Notebook basics

Jupyter Notebook is an aplicaton which enables you to create documents containing both code and explanations of the code in understandable language. Such documents are called ‘notebooks’. The code that you include in these notebooks can also be run (or executed) directly.

Jupyter notebook enables you to share your code and the documentation of this code in a very effective way.

Cells

A notebook is essentially a collection of cells. We shall be working with two types of cells.

  • A Code cell contains code to be executed using the so-called Python kernel. When you run a cell, the output will be displayed directly below the cell.

  • A Markdown cell contains rich text. The text can be formatted using a langauge named Markdown.

To view the markdown codes, you need to double click on the cell that contains this text. You can try this with this current cell.

The cell below contains code. Double clicking on this cell and try to edit the code.

# This cell contains code
print('Hello world!')

Cells can be run by placing the cursor inside the cell and by clicking on [Shift] + [Enter]. Alternatively, you can click on ‘Run’ in the menu at the top of the screen. Try to experiment with this. Can you change the output of the print() function, for instance?

Code cells always have the characters In [ ]: to their left. While the kernel is still active (i.e. when it is busy running the code), you will see an asterisk (‘*’) in between the two square brackets. When it has finished running, Jupyter Notebook will display a number. The program keeps track of the order in which you run all the cells.

You can also add new cells by choosing Insert > Insert Cell Above or Insert Cell Below from the menu. New cells will be code cells by default. If you want to change the newly created cell into a Markdown cell, you can use the drowdown menu at the top of your screen, containing values such as Code and Markdown.

To delete a cell, you can choose Edit > Delete cells.

# Click on this cell to insert a new cell below it. Next, try to to delete this cell

Finally, try to run the cell below.

import this