Python | sympy.sympify() method
Last Updated :
18 Jun, 2019
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.
from sympy import *
x, y = symbols( 'x y' )
expn = "x**2 + 3 * x - 1 / 2"
gfg = sympify(expn)
print (gfg)
|
Output :
x**2 + 3*x – 1/2
Example #2 :
from sympy import *
x, y = symbols( 'x y' )
expn = "x**2 + 3 * x - 1 / 2"
gfg = sympify(expn)
gfg = gfg.subs(x, 3 )
print (gfg)
|
Output :
35/2
Share your thoughts in the comments
Please Login to comment...