Interview prep

24 Jupyter interview questions, with answers.

Jupyter Notebook and JupyterLab questions for data roles: kernels, hidden state, magics, environments, version control and when a notebook should become real code.

Almost every data scientist uses Jupyter, so interviewers use it to tell everyday users from people who understand what's underneath. Expect questions on kernels and hidden state, magic commands, getting packages into the right environment, and how you make a notebook reproducible and reviewable.

The best answers show judgement: what notebooks are great for, where they go wrong, and when you'd move code into a module.

These 24 questions are free. SchoolWhool's Foundations of AI course places 650+ interview questions right after the lessons they test, with a mock interview with Gaurav. See also the machine learning interview questions.

Notebook basics

What is Jupyter, and how is Jupyter Notebook different from JupyterLab?
Jupyter is an open-source project for interactive computing; a notebook mixes code, its output and formatted text in one document. Jupyter Notebook is the simpler single-document interface (version 7 is built on JupyterLab components). JupyterLab is the fuller, IDE-like interface with tabs, a file browser, terminals and extensions. Both use the same .ipynb files and kernels.
What is inside an .ipynb file?
It's a JSON document: a list of cells (code, markdown or raw), each with its source, outputs and execution count, plus notebook metadata such as the kernel. Outputs are stored too, including images as base64. That's why notebook diffs are noisy and files grow large.
How do IPython and Jupyter relate?
IPython is an enhanced interactive Python shell, and its kernel (ipykernel) is what runs Python code in Jupyter. Jupyter grew out of IPython in 2014 to become language-agnostic, which is where the name (Julia, Python, R) comes from. Magic commands, rich display and tab completion come from IPython.
What's the difference between code, markdown and raw cells?
Code cells run in the kernel. Markdown cells render formatted text, links, images and LaTeX maths, and are where you explain why you did something. Raw cells are passed through unchanged when converting the notebook with nbconvert.
What are command mode and edit mode? Name a few shortcuts.
Press Esc for command mode (acting on whole cells) and Enter for edit mode (typing in a cell). Shift+Enter runs a cell and moves on; A and B insert a cell above or below; M and Y switch to markdown or code; D, D deletes; 0, 0 restarts the kernel. Knowing these shows you actually work in notebooks.

Kernels and execution

What is a kernel?
The separate process that executes your code and holds the notebook's state: variables, imports and loaded data. The browser interface talks to it over Jupyter's messaging protocol. Kernels exist for many languages, including Python (ipykernel), R and Julia.
What does restarting the kernel do, and when should you do it?
It kills the process and clears all state. Restart after installing or upgrading packages, after editing a module you've already imported, when memory is exhausted, and before sharing a notebook. Restart and Run All is the simplest test that a notebook really works from top to bottom.
What problems does out-of-order execution cause?
State depends on the order cells were run, not their order on the page. A variable from a deleted or edited cell still exists, so the notebook may work for you and fail for everyone else. The execution counts in brackets reveal the order; restart and run everything before trusting a result.
How do you use a virtual environment or conda environment as a kernel?
Install ipykernel in that environment and register it: python -m ipykernel install --user --name myenv --display-name 'Python (myenv)'. Then choose it from the kernel menu. A common mistake is installing packages into a different environment from the one the kernel runs in.
Why use %pip install instead of !pip install?
%pip installs into the environment of the running kernel. !pip runs whichever pip comes first on the shell's PATH, which may belong to a different Python, so the import still fails. The same goes for %conda. Restart the kernel if the package was already imported.
How do you interrupt or debug a cell?
Interrupt (I, I or the stop button) raises KeyboardInterrupt in the kernel. After an exception, %debug opens the post-mortem debugger at the failing line, and %pdb on does it automatically. JupyterLab also has a visual debugger with breakpoints.

Magics and tools

What are magic commands? What's the difference between line and cell magics?
Magics are IPython commands, not Python. Line magics start with % and apply to one line (%timeit, %run, %load_ext); cell magics start with %% and apply to the whole cell (%%time, %%writefile, %%bash). %lsmagic lists them all. Because they aren't valid Python, they break if you export a notebook to a script and run it with python.
%time or %timeit?
%time runs the code once and reports wall-clock and CPU time, which suits slow, one-off steps. %timeit runs a statement many times and reports the mean and spread, which suits small snippets. Keep setup, such as loading data, out of the timed code.
What does %autoreload do?
After %load_ext autoreload and %autoreload 2, imported modules are reloaded before each cell runs, so edits to your .py files take effect without restarting the kernel. It's ideal once you've moved code out of the notebook into modules. It isn't perfect: existing objects keep old class definitions, so restart if behaviour looks strange.
How do you display plots in a notebook?
Matplotlib plots render inline by default in modern Jupyter; %matplotlib inline makes it explicit. %matplotlib widget (the ipympl package) gives interactive zoom and pan. Plotly, Altair and Bokeh render interactive HTML outputs directly.
What are ipywidgets for?
Interactive controls, such as sliders, dropdowns and buttons, wired to Python code; interact(f, x=(0, 10)) turns a function into a small explorer. They're great for exploring parameters and for demos. For an app other people use, Voilà, Streamlit or Panel are better fits.
How do you reuse code from another notebook?
%run other.ipynb executes it in the current namespace, which works but hides where names come from. The better habit is to move shared functions into a .py module and import them, which also makes them testable.

Reproducibility and production

How do you make a notebook reproducible?
Pin dependencies in a requirements or lock file, set random seeds, load data with code and relative paths rather than from your desktop, and avoid relying on hidden state. Record library versions in the notebook. The final check is Restart and Run All in a fresh environment.
How do you put notebooks under version control?
Raw .ipynb diffs are noisy because outputs and metadata change. Strip outputs before committing (nbstripout as a pre-commit hook), use nbdime for notebook-aware diffs and merges, or pair each notebook with a plain script using Jupytext and review that in pull requests. Never commit secrets that were printed in an output.
How do you run a notebook from the command line or on a schedule?
jupyter nbconvert --to notebook --execute report.ipynb runs it and saves the outputs. Papermill adds parameters, via a cell tagged parameters, and saves an executed copy for each run, which is handy for scheduled reports. Anything long-lived belongs in scripts or a pipeline tool.
Should notebooks be used in production?
Usually they're for exploration and communication; production logic should live in tested modules and pipelines. Notebooks make testing, code review and modular design hard, and hidden state causes bugs. Reasonable exceptions are parameterised reports run with papermill, or platforms built around scheduled notebooks, and even then the core logic should be importable code.
How do you test code that lives in notebooks?
Move functions into modules and test them with pytest. Executing notebooks in CI (with nbconvert, nbval or testbook) catches notebooks that no longer run. Simple assert statements on shapes and values are a quick sanity check inside the notebook.
What security risks come with notebooks?
Running a notebook runs arbitrary code, so only run notebooks you trust. Jupyter's trust model stops untrusted notebooks from executing HTML and JavaScript outputs when opened. Never expose a Jupyter server to the internet without authentication, and keep credentials in environment variables, not cells.
How do you work with data that's too big for the notebook's memory?
Load only the columns and rows you need with sensible dtypes, read in chunks, store data as Parquet, and sample while exploring. Free memory with del on large objects, or use DuckDB, Polars or Dask. Huge printed outputs also bloat the notebook file, so print summaries, not whole tables.

First Principles, the SchoolWhool newsletter

One machine learning idea, explained properly, every week.

The intuition, the common mistake, and a five-minute way to try it yourself. Written by Gaurav.

Learn it properly, then the interview is the easy part.

Foundations of AI teaches Jupyter and the rest of machine learning from first principles, with notebooks that check your work.