Python Cell Reference

See Quick Start to see how to open the Code Editor for a Python cell in Quadratic.

Python Cells 101

Command + S runs the cell's code and keeps the Code Editor open.
Command + Enter runs a cell and closes the Code Editor.


OUTPUT (bottom right) is the stdout and the stderror of the code run in the cell.
Example: Showing Standard Out Powers of 2

Return Value

The Cell Value is set to the result of the last line of code. You can also explicitly set result to return something other than the last line of code.
Cell Value as the last line of code

Referencing Another Cell

To reference a single cell use the global function cell(x, y) or the shortcut c(x, y).
The resulting Cell object can be used directly in a Pythonic way. For example:
c(0, 0) + c(0, 1) # Adds cell 0, 0 and cell 0, 1
c(0, 0) == c(0, 1) # Is cell 0, 0 equal to cell 0, 1 ?
When a cell depends on other cells and the other cells update, this dependent cell will also update. Just like in Excel.
Example adding two cells together.

Returning a List of Cells

You can return a list of cells by returning a Python list of values.
For example: this will return the first 500 powers of 2 to the Grid.
result = []
for x in range(0, 500):
Returning the first 500 powers of 2 on the Grid

Referencing a Range of Cells

Referencing a range of cells in Quadratic is done using a Pandas DataFrame.
Learn more about DataFrames in Quadratic:

Using Python Packages

Use Micropip to install Python Packages in cells: