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!
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.
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:
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:
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.
[shift] + [enter] will execute the cell and give you the output in a new line, labeled
Out (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 addition to arithmetics, you can do comparisons with operators that return Boolean values (
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:
You can also define a variable (say
x) and assign it a value (say, 2), then use that variable in some code. Try it!
x = 2**8 x < 64
You learned about:
[shift] + [enter]to execute.