In [1]:
import sympy as sym
from IPython.display import display, Math
In [2]:
x = sym.symbols('x')

expr = 2*x + 4 -9
sym.solve(expr)
Out[2]:
[5/2]
In [3]:
display(Math('\\text{The solution to }%s\\text{ is }x = %g' %(sym.latex(expr),sym.solve(expr)[0])))
$\displaystyle \text{The solution to }2 x - 5\text{ is }x = 2.5$
In [4]:
sol=sym.solve(x**2-4)

type(sol)
len(sol)
print(sol)

for i in range(0,len(sol)):
    print('Solution #' + str(i+1) + ' is ' + str(sol[i]))
[-2, 2]
Solution #1 is -2
Solution #2 is 2
In [5]:
y = sym.symbols('y')
expr = x/4 - x*y + 5
sym.solve(expr,x)
Out[5]:
[20/(4*y - 1)]
In [6]:
sym.solve(expr,y)
Out[6]:
[(x + 20)/(4*x)]