您的位置:首页 > 编程语言 > Python开发

Python常用标准库 --- math

2017-03-03 15:13 218 查看
数字处理。

下面列出一些自己决定会用到的:
方法描述示例
math.pi返回圆周率>>> math.pi

3.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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: