What is Jupyter?

Jupyter is a way of computing and doing data science right on your browser. It gives you a Notebook — this document we're looking at now.

A Jupyter Notebook can contain: formatted text, images, videos, pretty math equations, and executable computer code. By "executable," we mean that you run the bits of code, right in the document, and get some output displayed for you. This interactive way of computing, mixed with the text, allows you to tell a story (even to yourself) with extra powers!

Jupyter Notebook App

If you are not running Jupyter locally on your computer, and want to see what the Jupyter Notebook App looks like, you can always try it using the free service at: https://try.jupyter.org.

After a few seconds, you should see the Dashboard, showing a list of available files, like this:


Click on the New button on the top right, and choose "Python 3" from the pull-down options. You should get an empty notebook with a single empty code cell labeled In[ ], and with a flashing cursor inside. You can start by trying any simple mathematical operation (like a calculator), and type [shift] + [enter] to execute it.

Notebook cells

The notebook uses cells to break things up into bits of text, and bits of code. This here is a Markdown cell: it contains text that you can format using simple markers to get headings, bold, italic, bullet points, hyperlinks, and more.

Here's a bit of history: Markdown was co-created by the legendary but tragic Aaron Swartz.

A few tips:

  • to create a title, use a hash to start the line: # Title
  • to create the next heading, use two hashes (and so on): ## Heading
  • to italicize a word or phrase, enclose it in asterisks (or underdashes): *italic* or _italic_
  • to make it bold, enclose it with two asterisks: **bolded**
  • to make a hyperlink, use square and round brackets: [hyperlinked text](url)

Look at the icons on the menu above. The first icon on the left (an old floppy disk) is for saving your notebook. You can add a new cell with the big + button. Then you have the cut, copy, and paste buttons. The arrows are to move your current cell up or down. Then you have a button to "run" a code cell, the square icon means "stop" and the swirly arrow is to "restart" your notebook (if the computation is stuck, for example). Next to that, you have the cell-type selector: Code or Markdown (or others that you can ignore for now).

A code cell will show you an input mark, like this:

In [ ]:

Once you execute the code, it will add a number id to the input cell, and produce an output marked like this:

Out [1]:

You can test-drive a code cell by writing some arithmetic operations; Python operators are:

+   -   *   /   **   %   //

There's addition, subtraction, multiplication and division. The last three operators are exponent (raise to the power of), modulo (divide and return remainder) and floor division.

Typing [shift] + [enter] will execute the cell and give you the output in a new line, labeled Out[1] (the numbering increases each time you execute a cell).

Try it! Add a cell with the plus button, enter some operations, and [shift] + [enter] to execute.

In [ ]:

In addition to arithmetics, you can do comparisons with operators that return Boolean values (True or False). These are:

==   !=   <   >   <=   >=

In a code cell, you can enter any valid Python code, and type [shift] + [enter] to execute it. For example, the simplest code example just prints the message Hello World!, like this:

print("Hello World!")

You can also define a variable (say x) and assign it a value (say, 2), then use that variable in some code. Try it!

In [1]:
print("Hello World!")
Hello World!
In [2]:
x = 2**8
x < 64

The world of Jupyter, so far

You learned about:

  • the notebook,
  • code cells and markdown cells,
  • the Jupyter Notebook App,
  • using a code cell like a calculator,
  • [shift] + [enter] to execute.

(c) 2017 Lorena A. Barba. Free to use under the Creative Commons Attribution CC-BY 4.0 License. Written for the tutorial "Data Science for a Better World", at the GW _Caminos al Futuro_ Summer program.