Skip to main content

Python and Markdown cells

Python cells#

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

Python cells can optionally have outputs, which are visualizations of elements from the code.

If any line of a Python 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 Python 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 Python cells - one with and one without an output

Markdown cells#

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

Hex uses 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 Python 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 Python to Markdown cells with esc + m
  • Go from Markdown to Python cells with esc + y
Option to convert a cell from the cell's upper-right dropdown menu