Facebook Page Twitter Page LinkedIn Page
× Python Tutorial Python Advanced Python Resources Python Libraries


The Python Math gcd() function is used to return the greatest common divisor of the specified arguments. The GCD of two numbers is the largest number that divides both of them.

For example - GCD of 20 and 25 is 5 and HCF of 50 and 100 is 50.

Syntax

gcd(a, b)

Parameters

a Required. Specify the first integer value.
b Required. Specify the second integer value.

Return Value

Returns the gcd of the specified arguments.

Example:

In the below example, gcd() function is used to return the gcd of the specified arguments.

import math

print(math.gcd(35, 49))
print(math.gcd(225, 100))
print(math.gcd(12, 42))

The output of the above code will be:

7
25
6

❮ Python Math Module