How to Use String Interpolation in Jupyter Notebook Markdown Cells

Emily Ekdahl
2 min readApr 7, 2021
Photo by Daniel Fazio on Unsplash

As a data professional, you may want to discuss results in a Jupyter Notebook markdown cell without hard coding the actual values in case they change. This is where string interpolation comes in!

String interpolation is a common practice in software development and is used to insert a variable and make it appear as text like the information around it.

Unfortunately, string interpolation does not work as intuitively in Jupyter Notebook markdown as it does in software development. Great news, the path to string interpolation in markdown cells has been forged for you!

Here are the steps I took to string interpolate text in a markdown cell.

First, install a Jupyter Notebook extension.

pip install jupyter_contrib_nbextensionsjupyter contrib nbextension install --user

Then, set it to enable python-markdown.

jupyter nbextension enable python-markdown/main

Start your Jupyter Notebook and create a variable or variables. Then, use the double curly braces to string interpolate your variable and execute the cell.

Hope this helps!

One small caveat, when I attempted to convert my notebook to PDF, the values did not display.

Special thanks to those who shared this information on stack overflow.

--

--