Code and Markdown Cells

Code Cells

Users can edit and execute any valid Python in a code cell.

Code cells can optionally have Outputs, which are visualizations of elements from the code.

If any line of a code cell explicitly prints a value (E.g: print("Hello!") ), that value will be included in the Output along with any other values explicitly printed by other lines.

Explicitly printed values from lines 2 and 3 are both included in Output

Lines that implicitly print a value (E.g: 2+2) are only included in Output if they occur on the last line of a code cell.

The implicit print of x on line 2 is not shown, though all explicit prints and the final implicit print are shown.

If a cell has no explicit print statements and the last line does not print a value explicitly or implicitly (E.g: x = 5), nothing is displayed as Output. This is perfectly fine, and is often done to keep things readable while setting the stage for another cell that will display something.

Examples of code cells - one with and one without an output

Markdown Cells

Markdown cells allow you to easily create richly-formatted text.

We use the Commonmark Markdown renderer - if you need help getting started with Markdown we recommend checking out their reference and tutorial.

Dynamic Markdown

You can also insert Python variables directly into Markdown cells. Type your text as usual but in place of hard-coding the value you want, wrap the variable name in {{ }} braces to dynamically update your Markdown text. See the screenshot below for an example.

Converting Cells

You can convert a cell from a Code to a Markdown cell and vice-versa using the dropdown in the upper right.

Or use keyboard shortcuts to convert between cell types:

  • Go from Code to Markdown cells with esc + m

  • Go from Markdown to Code cells with esc + y