Python | sympy.subs() method
With the help of sympy.subs() method, we can substitute the value of variables in the various mathematical functions by using the sympy.subs() method.
Syntax :
sympy.subs(source, destination)
Return : Return the same expression by changing the variable.
Example #1 :
In this example we can see that by using the sympy.subs() method, we can substitute the value of existing variable to the new variable.
# import sympy from sympy import * # symbol declaration x, y = symbols('x y') gfg_exp = cos(x) + 1 # use the method sympy.subs() gfg_exp = gfg_exp.subs(x, y) print(gfg_exp) |
Output :
cos(y) + 1
Example #2 :
# import sympy from sympy import * # symbol declaration x, y = symbols('x y') gfg_exp = cos(x) + 1 # use the method sympy.subs() gfg_exp = gfg_exp.subs(x, 0) print(gfg_exp) |
Output :
2
Recommended Posts:
- class method vs static method in Python
- Python | next() method
- Python | set() method
- Python | os.dup() method
- Python | os.getgroups() method
- Python | sympy.sec() method
- Python | Tensorflow tan() method
- Python | sympy.sin() method
- Python | os.getenvb() method
- Python | os.openpty() method
- Python | sympy.tan() method
- Python | sympy.nT() method
- Python | os.get_exec_path() method
- Python | sys.getrecursionlimit() method
- Python | os.getcwdb() 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.


