YouTip LogoYouTip

Ref Math Gcd

## Python math.gcd() Method The `math.gcd()` function returns the greatest common divisor of two integers. ### Syntax ```python math.gcd(a, b) ### Parameters * `a` - integer * `b` - integer ### Return Value Returns an integer representing the greatest common divisor of `a` and `b`. ### Example ```python import math print(math.gcd(6, 9)) # Output: 3 print(math.gcd(12, 18)) # Output: 6 print(math.gcd(17, 13)) # Output: 1 ### Note This function is available in Python 3.5 and above. For older versions, you can use the `fractions.gcd()` function from the `fractions` module. ```python from fractions import gcd print(gcd(6, 9)) # Output: 3 ### Related Articles
← Ref Math IsqrtRef Math Trunc β†’