Python | sympy.coeff(x, n) method
With the help of sympy.coeff(x, n) method, we are able to find the coefficient of variables in mathematical expressions.
Syntax :
sympy.coeff(x, n)
Return : Return the coefficient of variables.
Example #1 :
In this example, we can see that by using sympy.coeff(x, n) method, we can find the coefficient of mathematical expression.
# import sympy from sympy import * x, y, z = symbols('x y z') gfg_exp = x * y + x - 3 + 2 * x**2 - z * x**2 + x**3 # Using sympy.coeff(x, n) method gfg_exp = gfg_exp.coeff(x, 2) print(gfg_exp) |
chevron_right
filter_none
Output :
2 – z
Example #2 :
# import sympy from sympy import * x, y, z = symbols('x y z') gfg_exp = z * x + x - 3 + 2 * x**2 - y * x**2 + y**3 # Using sympy.coeff(x, n) method gfg_exp = gfg_exp.coeff(y, 1) print(gfg_exp) |
chevron_right
filter_none
Output :
-x**2
Recommended Posts:
- class method vs static method in Python
- Python | os.dup() method
- Python | set() method
- Python | next() method
- Python | os.scandir() method
- Python | cmath.log() method
- Python | os.ctermid() method
- Python | os.getppid() method
- Python | Tensorflow abs() method
- Python | cmath.exp() method
- Python | os.strerror() method
- Python | sys.getrecursionlimit() method
- Python | os.readv() method
- Python | Tensorflow log() method
- Python | os.writev() 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.



