导入math
import math
常用常数
>>> math.pi
3.141592653589793
>>> math.e
2.718281828459045
幂函数和对数函数
math.pow(x,y)返回x的y次幂
>>> math.pow(2,4)
16.0
>>> math.pow(4,1/2)
2.0
sqrt(x) 平方根
>>> math.sqrt(16)
4.0
exp(x) e的x次幂
>>> math.exp(1)
2.718281828459045
对数函数
>>> math.log2(4)
2.0
>>> math.log10(100)
2.0
log()默认以e为底
>>> math.log(math.e)
1.0
>>> math.log(10,10)
1.0
三角函数
余弦函数
>>> math.cos(math.pi)
-1.0
反余弦函数
>>> math.acos(-1)
3.141592653589793
其他三角函数类似,但是没有cot函数
角度转换
>>> math.degrees(math.pi)
180.0
>>> math.radians(180)
3.141592653589793
取整函数
向上取整
>>> math.ceil(3.4)
4
向下取整
>>> math.floor(3.4)
3
绝对值函数
>>> math.fabs(-5)
5.0
取余函数
>>> math.fmod(5,2)
1.0
>>> math.fmod(6,2)
0.0
阶乘函数
>>> math.factorial(5)
120
最大公约数
>>> math.gcd(5,2)
1
>>> math.gcd(4,2)
2