# 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) `

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) `

Output :

-x**2

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.