math简介
>>> import math
>>> dir (math)
>>> help (math)
标准库函数
Python Math 函数 必须 import math
函数类型 | 参数功能 |
---|
math.acos(x) | 返回 x 的反余弦 |
math.acosh(x) | 返回 x 的反双曲余弦 |
math.asin(x) | 返回 x 的反正弦 math.asin(x) |
math.asinh(x) | 返回 x 的反双曲正弦 |
math.atan(x) | 返回 x 的反正切 |
math.atan2(y,x) | 返回 y/x 的反正切 |
math.atanh(x) | 返回 x 的反双曲正切 |
math.ceil(x) | 返回≧ x 的最小整數 math.floor(3.4) 结果 4 |
math.copysign(x,y) | 返回与 y 同号的 x 值 math.copysign(x,y) |
math.cos(x) | 返回 x 的余弦 |
math.cosh(x) | 返回 x 的双曲余弦 math.cosh(x) |
math.degrees(x) | 將 x (弧长) 转成角度,与 radians 为反函数 math.degrees(x) |
math.erf(x) | x 的误差函数 |
math.erfc(x) | 互补误差函数 |
math.exp(x) | 返回以e为底数的x幂次方 |
math.expml(x) | 指数减一,即exp(x) - 1 |
math.fabs(x) | 返回 x 的绝对值 |
math.factorial(x) | 返回 x! |
math.floor(x) | 返回 ≦ x 的最大整数 math.floor(3.4) 结果 3 |
math.fmod(x,y) | 返回 x对y取模的余数,fmod 类似 %,但产生的结果可能与%不同,因为前者以y来决定余数的符号,后者你x来决定余数的符号。 |
math.frexp(x) | 返回一個 2 元組 (2-tuple) 分別是假数 m (float)以及一个指数 n(int),也就是 x = m×2n 与 ldexp 是反函数 math.frexp(x) math.frexp(1.625) 结果 (0.8125,1) |
math.fsum(x) | 返回 x 阵列值的各項和 math.frexp([2,5]) 结果 7 |
math.gamma(x) | gamma()函数,当函数变量x为正整数时,函数的值就是前一个整数的阶乘 |
math.(x, y, /) | 返回两个或多个整数的最大公约数 |
math.hypot(x,y) | 计算直角三角形的斜边长 |
isclose(a, b, *, rel_tol = 1e-09, abs_tol = 0.0) | python3.5新增函数,用于判断两个浮点数的值是否接近或相等,a和b是两个需要比较的浮点数,rel_tol表示相当于输入值的大小,被认为是“接近”的最大差异,abs_tol表示无论输出值的大小,被认为“接近”的最大差异,返回True |
math.isfinite(x) | 如果 x = ∞或者为缺失值,返回True |
math.isinf(x) | 如果 x = ±inf 也就是 ±∞,返回 True |
math.isnan(x) | 如果 x = Non (not a number)返回 True |
math.ldexp(m,n) | 返回 m×2n与 frexp 是反函数 |
math.lgamma(x) | 计算自然对数的gamma()函数的绝对值 |
math.log(x,a) | 返回x的自然对数 ,若不写a 內定 e |
math.log10(x) | 返回以10为底数的x的自然对数 |
math.loglp(x) | 返回以e为底数的x+1的自然对数 |
math.log2(x) | 返回以2为底数的x的自然对数 |
math.modf(x) | 返回 x 的小数部份与整数部份 |
math.pi | 返回常数 π (3.14159…) |
math.pow(x,y) | 返回 x**y,即x的y次方 |
math.radians(d) | 将 x(角度) 转成弧长,与 degrees 为反函数 |
math.remainder(x, y) | 返回一个整数除以另一个整数之后产生的余数 |
math.sin(x) | 返 x 的正弦 |
math.sinh(x) | 返回 x 的双曲正弦 |
math.sqrt(x) | 返回x的平方根 |
math.tan(x) | 返回 x 的正切 |
math.tanh(x) | 返回 x 的双曲正切 |
math.trunc(x) | 返回 x 的整数部份,等同 int |