Getting started with Jupyter notebooks: install, run cells, avoid hidden state

A Jupyter notebook is a document made of cells. Code cells run in a live interpreter (the kernel) and show their output (text, tables, plots) directly underneath; Markdown cells hold notes, headings and LaTeX equations. That mix makes notebooks popular for data exploration, teaching and sharing an analysis along with its results.
Notebooks are saved as .ipynb files, which are JSON containing the cells and their most recent outputs. The name comes from Julia, Python and R, and kernels exist for those and many other languages, but Python (via the ipykernel package) is by far the most common.
Installing and launching
Section titled “Installing and launching”The simplest route is pip, ideally inside a virtual environment:
python -m venv .venvsource .venv/bin/activate # Windows: .venv\Scripts\activatepip install jupyterlabjupyter labjupyter lab starts a local server and opens JupyterLab in your browser. Create a new notebook from the launcher by picking the Python 3 kernel.
Alternatives:
pip install notebookandjupyter notebookgive you the classic single-document interface. Notebook 7 is built on JupyterLab components, so the two look similar.- VS Code opens
.ipynbfiles directly once the Python and Jupyter extensions are installed; it still needsipykernelin the selected environment. - The Anaconda distribution (from Anaconda, Inc., formerly Continuum Analytics) bundles JupyterLab with NumPy, pandas, Matplotlib and other scientific packages. Check its terms of service before using it in an organisation.
Running cells
Section titled “Running cells”Type into a code cell and press Shift+Enter to run it and move to the next cell:
a = 3b = 5c = a + bprint("The sum of", a, "and", b, "is", c)Output:
The sum of 3 and 5 is 8Variables live in the kernel, not in the cell, so a later cell can use them:
c * 2The last expression in a cell is displayed automatically (here 16), which is why notebooks often end a cell with a bare DataFrame or chart object instead of a print.
A few other basics:
- Esc switches to command mode, where A/B insert a cell above/below, M turns a cell into Markdown and Y back into code.
- Tab completes names, and Shift+Tab shows a function’s signature and docstring.
%timeit exprtimes an expression, and!pip install packageruns a shell command. Prefer%pip install package, which installs into the kernel’s environment rather than whicheverpipis first on yourPATH.
Pitfalls
Section titled “Pitfalls”- Hidden state. Cells can be run in any order, and deleting a cell doesn’t delete the variables it created. A notebook can work for you and fail for someone else. Before sharing, use Kernel → Restart Kernel and Run All Cells to check it runs top to bottom.
- Noisy version control. Because
.ipynbstores outputs and execution counts, diffs are hard to read. Tools like nbstripout strip outputs on commit, and Jupytext pairs each notebook with a plain.pyor.mdfile. - Notebooks aren’t modules. Once code stabilises, move functions into a
.pyfile and import them; that makes them testable and reusable.
Further reading
Section titled “Further reading”© 2026 David Li · Home · Blog · RSS ·Classic site · Built with Astro, Starlight and three.js · Logos:Font Awesome Free (CC BY 4.0)