Friday, November 21, 2025
HomeLanguagesPython | sympy.as_coefficient() method

Python | sympy.as_coefficient() method

With the help of sympy.as_coefficient() method, we can find the coefficient of any element in the mathematical expression by using sympy.as_coefficient() method.

Syntax : sympy.as_coefficient()
Return : Return the coefficient of any element.

Example #1 :
In this we can see that by using sympy.as_coefficient() method, we are able to get the values of coefficient of any element that is passed as parameter.




# import sympy
from sympy import * 
  
x = symbols('x')
  
# Use sympy.as_coefficient() method
gfg = x**3 + 21 * x + 12
  
print(gfg.as_coefficient(x))


Output :

21

Example #2 :




# import sympy
from sympy import * 
  
x = symbols('x')
  
# Use sympy.as_coefficient() method
gfg = x**3 + 21 * x**2 + 121x + 4
  
print(gfg.as_coefficient(x))


Output :

121

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32405 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6781 POSTS0 COMMENTS
Nicole Veronica
11928 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11995 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7166 POSTS0 COMMENTS
Thapelo Manthata
6862 POSTS0 COMMENTS
Umr Jansen
6847 POSTS0 COMMENTS