Python code in Jupyter notebooks#

Python code can be written in “.py” files, which can be executed from command line. Furthermore, for academic purposes, Jupyter notebooks are often used to document what code does and add additional explanations and links to resources.

See also

To write our first small python program, we type in the Jupyter notebook code cell below. You can double click in this cell, change the code and execute it by hitting SHIFT+ENTER:

print("Hello world")
Hello world
  • When working with Jupyter notebooks, obviously SHIFT-ENTER is the short cut people use all the time.

  • If you want to “leave” a cell without executing it, you can also hit ESCAPE.

  • You can add a new cell above the current cell by hitting A and below by hitting B.

  • You can delete cells by hitting D.

There are more shortcuts. You can see them all in the menu above Help > Keyboard shortcuts or by hitting H.

Try it out!

Markdown documentation in Jupyter notebooks#

Markdown is a coding language for describing the formating ~of~ text. In order to see the markdown code which describes this text, double click this cell in your Jupyter notebook. Hit SHIFT+ENTER to return to the viewing mode.

  • Bullet point

  • More bullet points

    • Deeper bullet points

  1. List entry

  2. Another list entry

  3. More list entries

  4. Markdown cheatsheet

Exercise#

Add a new python code cell below and use the print command to print your name.