Python的内置函数math.gcd()用于计算两个整数的最大公约数(greatest common divisor,GCD)。该函数接受两个参数,这两个参数都应该是整数。
参数限制如下:
参数必须是整数。如果传入非整数类型的参数,将会引发TypeError。参数不能为负数。如果传入负数,将会引发ValueError。以下是一个使用math.gcd()函数的示例:
import matha = 56b = 98result = math.gcd(a, b)print(f"The GCD of {a} and {b} is {result}")输出结果:
The GCD of 56 and 98 is 14 

