首页 > 编程 > Python > 正文

Python常用标准库 --- math

2019-11-06 08:13:11
字体:
来源:转载
供稿:网友

数字处理。

下面列出一些自己决定会用到的:

方法描述示例
math.pi返回圆周率>>> math.pi3.141592653589793
math.ceil(x)返回x浮动的上限>>> math.ceil(5.2)6.0
math.floor(x)返回x浮动的下限>>> math.floor(5.2)5.0
math.trunc(x)将数字截尾取整>>> math.trunc(5.2)5
math.fabs(x)返回x的绝对值>>> math.fabs(-5.2)5.2
math.fmod(x,y)返回x%y(取余)>>> math.fmod(5,2) 1.0
math.modf(x)返回x小数和整数>>> math.modf(5.2)(0.20000000000000018, 5.0)
math.factorial(x)返回x的阶乘>>> math.factorial(5)120
math.pow(x,y)返回x的y次方>>> math.pow(2,3)8.0
math.sPRt(x)返回x的平方根>>> math.sqrt(5)

2.2360679774997898


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表