Jupyter Notebooks#
Throughout the semester, we will use Jupyter Notebooks.
What are Jupyter Notebooks?#
From Jupyer Notebook: An IntroductionThe Jupyter Notebook is an open source web application that you can use to create and share documents that contain live code, equations, visualizations, and text. Jupyter Notebook is maintained by the people at Project Jupyter.
Jupyter Notebooks are a spin-off project from the IPython project, which used to have an IPython Notebook project itself. The name, Jupyter, comes from the core supported programming languages that it supports: Julia, Python, and R. Jupyter ships with the IPython kernel, which allows you to write your programs in Python, but there are currently over 100 other kernels that you can also use.
Note that Anaconda is a popular distribution of Python that comes with Jupyter Notebooks.
Starting a Jupyter Notebook server#
Open your terminal application (Terminal on MacOS, Anaconda Prompt on Windows)
Change your current directory to a location on your computer where you would like to save your notebook (for example:
cd /Users/home/notebooks)Run the command
jupyter notebookwhich will start your default browser (or open a new tab) to the following URL: http://localhost:8888/tree

Interactive Coding#
We will use Jupyter Notebooks to interface with Python. Rather than keeping code scripts code and execution separate, Jupyter integrates both together using the concept of cells. Two main types of cells are code cells and markdown cells. Cells pair “snippets” of code with the output obtained from running them and can contain plots/figures inline alongside code required to generate them.
Code cells contain actual code that you want to run. You can specify a cell as a code cell using the pulldown menu in the toolbar in your Jupyter notebook. If you want to execute the code in a code cell, hit “shift + enter”. Note that code cells are executed in the order you execute them. That is to say, the ordering of the cells for which you hit “shift + enter” is the order in which the code is executed. If you did not explicitly execute a cell early in the document, its results are now known to the Python interpreter.
Markdown cells contain text. The text is written in Markdown, a lightweight markup language. You can read about its syntax here. See this comprehensive guide to Markdown or tutorial. Note that you can also insert HTML into markdown cells, and this will be rendered properly. As you are typing the contents of these cells, the results appear as text. Hitting “shift + enter” renders the text in the formatting you specify.
In general, when you want to add a new cell, you can use the “Insert” pulldown menu from the Jupyter toolbar. The shortcut to insert a cell below is “esc, b” and to insert a cell above is “esc, a”. Alternatively, you can execute a cell and automatically add a new one below it by hitting “alt + enter”.
# This is a code cell
# Put some code here and get some output below!
x = 10
print(x)
10