Get AI summaries of any video or article — Sign up free
Jupyter Notebook Tutorial: Introduction, Setup, and Walkthrough thumbnail

Jupyter Notebook Tutorial: Introduction, Setup, and Walkthrough

Corey Schafer·
6 min read

Based on Corey Schafer's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.

TL;DR

Jupyter Notebooks let users edit and rerun individual cells so plots and outputs update immediately in the browser.

Briefing

Jupyter Notebooks turn code, results, plots, and explanations into a single interactive document—so users can run computations in small steps, see outputs immediately in the browser, and even reproduce published research workflows. The tutorial opens by contrasting notebooks with static formats like PDFs: charts are generated live by the code, and changing a parameter (like a plot label) and rerunning a single cell updates the visualization instantly. That interactive loop—edit, execute, inspect—helps explain why scientific groups and research teams increasingly publish notebooks alongside their findings, including an example inspired by LIGO’s gravitational-wave work, where markdown instructions sit next to executable Python and generated figures.

From there, the walkthrough focuses on getting started. Installation is recommended via Anaconda because it bundles Jupyter, though pip-based installation is also available. After starting a notebook server (defaulting to localhost port 8888), the user creates a new notebook by selecting an appropriate kernel—essentially the programming-language runtime. The tutorial then emphasizes the notebook’s two operating modes: command mode for managing cells (add, delete, move) and edit mode for changing cell contents. Keyboard shortcuts are highlighted for switching modes and for executing cells.

Execution behavior is treated as a core concept. Running a cell can either keep focus on the current cell, move selection to the next cell, or insert a new cell below—each with different outcomes. The tutorial also explains why notebooks behave unlike traditional scripts: cells don’t have to run top-to-bottom. Instead, the “In [ ] / Out [ ]” numbering tracks the order of execution, which can cause variables to hold values from earlier runs even if the assignment appears later in the document. When state gets confusing, “Run all” restores a top-to-bottom execution order, and there are options to run only cells above or below the current one.

To make notebooks readable, the tutorial shows how to add markdown cells that render into HTML (headers, lists, emphasis, and more). It then introduces notebook “special commands” and “magics.” A leading exclamation mark runs bash commands directly (for example, pip list). Magics—prefixed with % or %%—provide notebook-specific utilities such as %lsmagic to list available commands, %pwd and %ls to inspect the environment, and %matplotlib inline to display Matplotlib plots inside the notebook. Without that inline setting, plotting can appear to hang until the kernel is restarted.

Additional cell magics demonstrate richer output: rendering HTML via %%html (including embedding an iframe), executing JavaScript, and timing code with %timeit. The tutorial also shows that simply printing a pandas DataFrame renders it neatly in the notebook, making exploratory data analysis more convenient than running separate scripts.

Finally, it covers practical workflow features: exporting notebooks to formats like HTML for sharing, understanding that notebook files are JSON under the hood, and creating multiple kernels—such as Python 2—either through Anaconda environments or pip-based kernel installation. To build familiarity, it points to Jupyter/IPython galleries on GitHub where users can download example notebooks (like numerical integration tutorials) and inspect the exact code behind the results.

Cornell Notes

Jupyter Notebooks combine executable code, rendered text (markdown), and live outputs like plots and DataFrame tables in one document. The key operational idea is that cells run independently: execution order is tracked by the “In [ ] / Out [ ]” numbers, so variables can change based on what was run earlier rather than what appears earlier. The tutorial shows how to install Jupyter (preferably via Anaconda), start a local notebook server, choose kernels, and use command/edit modes. It also demonstrates notebook magics and special commands—running bash with “!” and using %/%% magics for tasks like listing magics, enabling inline Matplotlib, rendering HTML, and timing code. Exporting notebooks to HTML and using multiple kernels (including Python 2 via Anaconda environments) rounds out the setup for sharing and experimentation.

Why do Jupyter Notebooks feel different from running a Python script top-to-bottom?

Notebook cells don’t have to execute in document order. The “In [ ] / Out [ ]” numbering shows the actual execution sequence, and variable state persists across cells. For example, assigning name = John in one cell and then running a later cell that prints name will output John; if name is reassigned to Corey in another cell and the earlier print cell is rerun, it will print Corey even though the assignment appears later in the notebook. When results look wrong, checking those execution numbers (or using “Run all”) helps restore a predictable order.

What’s the practical difference between command mode and edit mode in a notebook?

Command mode (Escape) is for managing cells—adding, deleting, and selecting cells to perform actions. Edit mode (Enter or clicking into a cell) is for changing the cell’s contents; the UI highlights the cell (e.g., green highlight) and shows an edit-mode indicator like a pencil icon. Switching back to command mode removes the edit indicator and changes the cell selection styling (e.g., blue).

How do you execute a cell, and what do the three run options change?

The tutorial distinguishes three execution behaviors: “Run” executes the current cell and keeps it selected; “Run cell and select below” executes the current cell and moves selection to the next cell (inserting one if needed); “Run cell and insert below” executes the current cell and inserts a new cell below even if an empty cell already exists. On Mac, the shortcuts given are: Control+Enter (execute and stay), Shift+Enter (execute and select below), and Enter (execute and insert below).

What are “magics,” and how do they help beyond normal Python?

Magics are notebook-specific commands prefixed with % (line magics) or %% (cell magics). They enable environment inspection and notebook features without writing extra Python. Examples include %lsmagic to list available magics, %pwd to print the working directory, and %ls or %ls -la to list files. For plotting, %matplotlib inline is crucial so Matplotlib figures render inside the notebook; without it, the tutorial shows a plot cell can appear to spin/hang until the kernel is restarted and the inline magic is run first.

How can notebooks display rich content like plots, HTML, and DataFrames?

Plots are displayed by enabling inline Matplotlib (%matplotlib inline) and then running plotting code. HTML can be rendered using the cell magic %%html, such as embedding an iframe to show another webpage or video inside the notebook. DataFrames from pandas can be displayed just by printing them (e.g., creating a DataFrame and then running it or using df.head); the notebook renders the output in a readable table format without extra formatting code.

How do kernels and multiple Python versions fit into notebook setup?

A kernel determines which programming language/runtime a notebook cell uses. The tutorial shows selecting Python 3 as “python root” (kernel). It also demonstrates that Python 2 can appear as a separate kernel (e.g., “python 2 kernel” shown as Python 27 in Anaconda environments). With Anaconda, installing Jupyter within virtual environments makes those environments show up as selectable kernels; without Anaconda, Python 2 kernel installation requires following pip-based instructions from Jupyter’s site.

Review Questions

  1. What problems can arise if you assume notebook cells run strictly from top to bottom, and how do the “In [ ] / Out [ ]” numbers help diagnose them?
  2. Which magic command enables Matplotlib plots to render inside the notebook, and what happens if you try to display a plot without it?
  3. How do the three execution options (run, run and select below, run and insert below) differ in terms of cell selection and insertion?

Key Points

  1. 1

    Jupyter Notebooks let users edit and rerun individual cells so plots and outputs update immediately in the browser.

  2. 2

    A notebook’s two modes—command mode and edit mode—control whether the user manages cells or edits cell content.

  3. 3

    Execution order is independent of visual order; “In [ ] / Out [ ]” numbers track what ran when and can affect variable values.

  4. 4

    Markdown cells render into formatted HTML, making notebooks readable like a tutorial or report with embedded results.

  5. 5

    Notebook magics (% and %%) and “!” shell escapes enable environment commands, inline plotting, HTML rendering, and timing without leaving the notebook.

  6. 6

    Exporting notebooks (e.g., to HTML) supports sharing code plus outputs, and notebook files are stored as JSON.

  7. 7

    Multiple kernels allow different runtimes (such as Python 2 vs Python 3), typically managed via Anaconda environments or kernel installation steps.

Highlights

Changing a parameter in a single cell and rerunning it regenerates the plot instantly, illustrating why notebooks are useful for interactive exploration.
Notebook state persists across cells: variables can reflect earlier runs even if the assignment appears later in the document.
%matplotlib inline is a make-or-break setting for displaying Matplotlib figures inside the notebook; skipping it can lead to a stalled-looking plot cell.
%%html can embed rich content like an iframe directly inside the notebook output area.
Jupyter notebooks can be exported to HTML for sharing, while the underlying .ipynb file is just JSON.

Topics

  • Jupyter Notebooks Setup
  • Kernels and Execution Order
  • Markdown and Cell Modes
  • Magics and Inline Plotting
  • Exporting Notebooks

Mentioned