1.math简介
>>> import math
>>>dir(math) #这句可查看所有函数名列表
[‘__doc__‘, ‘__name__‘, ‘__package__‘, ‘acos‘, ‘acosh‘, ‘asin‘, ‘asinh‘, ‘atan‘, ‘atan2‘, ‘atanh‘, ‘ceil‘, ‘copysign‘, ‘cos‘, ‘cosh‘, ‘degrees‘, ‘e‘, ‘erf‘, ‘erfc‘, ‘exp‘, ‘expm1‘, ‘fabs‘, ‘factorial‘, ‘floor‘, ‘fmod‘, ‘frexp‘, ‘fsum‘, ‘gamma‘, ‘hypot‘, ‘isinf‘, ‘isnan‘, ‘ldexp‘, ‘lgamma‘, ‘log‘, ‘log10‘, ‘log1p‘, ‘modf‘, ‘pi‘, ‘pow‘, ‘radians‘, ‘sin‘, ‘sinh‘, ‘sqrt‘, ‘tan‘, ‘tanh‘, ‘trunc‘]
>>>help(math) #查看具体定义及函数0原型
>>>help(math.function) #查看math模块下函数的功能
2.常用函数
ceil(x) 取顶
Return the ceiling of x as a float.
This is the smallest integral value >= x.
floor(x) 取底
Return the floor of x as a float.
This is the largest integral value <= x.
fabs(x) 取绝对值
Return the absolute value of the float x.
factorial (x) 阶乘
Find x!. Raise a ValueError if x is negative or non-integral.
hypot(x,y) 求直角三角形的斜边长
Return the Euclidean distance, sqrt(x*x + y*y)
pow(x,y) x的y次方
Return x**y (x to the power of y).
sqrt(x) 开平方
Return the square root of x.
log(x[,base])
Return the logarithm of x to the given base.
If the base not specified, returns the natural logarithm (base e) of x.
log10(x)
Return the base 10 logarithm of x.
trunc(x) 截断取整数部分
Truncates x to the nearest Integral toward 0. Uses the __trunc__ magic method.
isnan (x) 判断是否NaN(not a number)
Check if float x is not a number (NaN)
degrees(x) 弧度转角度
Convert angle x from radians to degrees.
radians(x) 角度转弧度
Convert angle x from degrees to radians.
另外该模块定义了两个常量:
e = 2.718281828459045
pi = 3.141592653589793