Skip to content

Defining Varaibles

Defining Varaibles

Before we can construct symbolic math expressions or symbolic math equations, we first need to create symbolic math variables, also called symbolic math symbols.

To define symbolic math variables with SymPy, first import the symbols() function from the SymPy module:

In [1]:
from sympy import symbols

Symbolic math symbols are declared using SymPy's symbols() function. A string is passed to the symbols() function as an input argument and the output is assigned to a SymPy symbols object (not a string).
In [2]:
x = symbols('x')
y = symbols('y')

SymPy's symbol() function can define multiple symbols in the same line of code. Note the input arguments passed to the symbols() function is a string, entries separated by a space (no comma) and surrounded by quotes. The output of the symbols() function are SymPy symbol objects. Commas separate these output objects (no quotation marks).
In [3]:
x, y = symbols('x y')