Running and Quitting

Overview

Teaching: 15 min
Exercises: 0 min
Questions
  • How can I run Python programs?

Objectives
  • Launch the Jupyter Notebook, create new notebooks, and exit the Notebook.

  • Create Markdown cells in a notebook.

  • Create and run Python cells in a notebook.

Getting the Data

The data we will be using is taken from the [gapminder][gapminder] dataset. Create a directory called python-novice-gapminder, and download the zip file python-novice-gapminder-data.zip into it. Then unzip the file (it should create a data folder. Then start a Jupyter notebook from inside this directory (see the second header below).

Python programs are plain text files.

Use the Jupyter Notebook for editing and running Python.

Example Jupyter Notebook
Screenshot of a Jupyter Notebook on quantum mechanics by Robert Johansson

How It’s Stored

  • The notebook file is stored in a format called JSON.
  • Just like a webpage, what’s saved looks different from what you see in your browser.
  • But this format allows Jupyter to mix software (in several languages) with documentation and graphics, all in one file.

Use the keyboard and mouse to select and edit cells.

Use comments to add documentation to programs.

# This sentence isn't executed by Python.
adjustment = 0.5   # Neither is this - anything after '#' is ignored.

More Math

What is displayed when a Python cell in a notebook that contains several calculations is executed? For example, what happens when this cell is executed?

7 * 3
2 + 1

Solution

Python returns the output of the last calculation.

3

Key Points

  • Python programs are plain text files.

  • Use the Jupyter Notebook for editing and running Python.

  • The Notebook has Command and Edit modes.

  • Use the keyboard and mouse to select and edit cells.

  • The Notebook will turn Markdown into pretty-printed documentation.

  • Markdown does most of what HTML does.