简介
import math
dir(math) #这句可查看所有函数名列表
help(math) #查看具体定义及函数0原型
常用函数
ceil(x) 取顶
floor(x) 取底
fabs(x) 取绝对值
factorial (x) 阶乘
hypot(x,y) sqrt(xx+yy)
pow(x,y) x的y次方
sqrt(x) 开平方
log(x)
log10(x)
trunc(x) 截断取整数部分
isnan (x) 判断是否NaN(not a number)
degree (x) 弧度转角度
radians(x) 角度转弧度
例如
>>> math.degrees(math.pi)
180.0
>>> math.sqrt(3)
1.7320508075688772
函数模型中的两个常量
e = 2.718281828459045
pi = 3.141592653589793
>>> math.e
2.718281828459045