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