Python | sympy.sympify() method
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.
# 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 :
# 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
Recommended Posts:
- class method vs static method in Python
- Python | os.dup() method
- Python | next() method
- Python | set() method
- Python | os.set_inheritable() method
- Python | cmath.exp() method
- Python | os.urandom() method
- Python PIL | putalpha() Method
- Python PIL | putdata() method
- Python | sympy RGS method
- Python | sympy.ff() method
- Python | os.times() method
- Python PIL | eval() method
- Python | sympy.rf() method
- Python PIL | RankFilter() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



