小白教程
所有教程
关于
Search
172.70.126.176
172.70.126.176
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Ref math gcd”的源代码
本页内容
上一节:
Ref_math_gamma
下一节:
Ref_math_hypot
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:math.gcd()}}[[Category:python math|31]] = Python math.gcd() 方法 = [[python math|Python math 模块]] Python '''math.gcd()''' 方法返回给定的整数参数的最大公约数。 gcd(0,0) 返回 0。 Python 版本:3.5 在 3.9 版更改: 添加了对任意数量的参数的支持,之前的版本只支持两个参数。 === 语法 === math.gcd() 方法语法如下: <sample title="" desc="" lang="python" hererun="1"> math.gcd(*integers) </sample> '''参数说明:''' * '''*integers''' -- 必需,数字。如果 x 不是一个数字,返回 TypeError。 === 返回值 === 返回一个整数 int,表示两个或多个整数的最大公约数 (GCD)。 == 以下实例返回数字的最大公约数: <sample title="" desc="" lang="python" hererun="1"> # 导入 math 包 import math # 输出最大公约数 print (math.gcd(3, 6)) print (math.gcd(6, 12)) print (math.gcd(12, 36)) print (math.gcd(-12, -36)) print (math.gcd(5, 12)) print (math.gcd(10, 0)) print (math.gcd(0, 34)) print (math.gcd(0, 0)) </sample> 输出结果: <sample title="" desc="" lang="python" hererun="1"> 3 6 12 12 1 10 34 0 </sample> [[python math|Python math 模块]]
返回至“
Ref math gcd
”。
上一节:
Ref_math_gamma
下一节:
Ref_math_hypot