The Wayback Machine - https://web.archive.org/web/20250529161737/https://www.geeksforgeeks.org/python-sympy-sympify-method/
Open In App

Python | sympy.sympify() method

Last Updated : 18 Jun, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
With the help of sympy.sympify() method, we are able to convert the expression of string type to general mathematical expression.
Syntax : sympy.sympify() Return : Return the expression.
Example #1 : In this example we can see that by using sympy.sympify(), we are converting the string of expression into real mathematical expression. Python3 1=1
# Import sympy
from sympy import *

# Define symbols and trigo expression
x, y = symbols('x y')
expn = "x**2 + 3 * x - 1 / 2"

# Use sympy.sympify() method
gfg = sympify(expn)

print(gfg)
Output :
x**2 + 3*x - 1/2
Example #2 : Python3 1=1
# Import sympy
from sympy import *

# Define symbols and trigo expression
x, y = symbols('x y')
expn = "x**2 + 3 * x - 1 / 2"

# Use sympy.sympify() method
gfg = sympify(expn)
gfg = gfg.subs(x, 3)

print(gfg)
Output :
35/2

Next Article
Article Tags :
Practice Tags :

Similar Reads