Related Articles

# Python | sympy.gcd() method

• Last Updated : 17 Sep, 2019

The function `gcd()` provides the direct way to compute Greatest Common Divisor for polynomials.That is, for polynomials f and g, it computes GCD.
```Syntax: sympy.gcd(f, g)

Return: GCD of given polynomials
```

Example #1:

 `# import sympy  ``from` `sympy ``import` `*` `f ``=` `(``12` `*` `x ``+` `12``)``*``x``g ``=` `32` `*` `x``*``*``2`` ` `# Using sympy.gcd() method ``gfg ``=` `gcd(f, g)  `` ` `print``(gfg)`

Output:

`4*x`

Example #2:

 `# import sympy  ``from` `sympy ``import` `*` `f ``=` `3` `*` `x``*``*``2` `/` `2``g ``=` `9` `*` `x ``/` `4`` ` `# Using sympy.gcd() method ``gfg ``=` `gcd(f, g)  `` ` `print``(gfg)`

Output:

`x`

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up