Python 数学模块
Python 有一个用于执行数学任务内置模块。
math 模块有一组方法和常量。
数学方法
| 方法 | 描述 |
|---|---|
| math.acos() | 返回数的反余弦值。 |
| math.acosh() | 返回数的双曲反余弦值。 |
| math.asin() | 返回数的反正弦值。 |
| math.asinh() | 返回数的双曲反正弦值。 |
| math.atan() | 返回数的反正切值,以弧度为单位。 |
| math.atan2() | 返回 y/x 的反正切值,以弧度为单位。 |
| math.atanh() | 返回数的双曲反正切值。 |
| math.ceil() | 将数字向上舍入到最接近的整数。 |
| math.comb() | 返回从 n 个项目中不重复且不排序地选择 k 个项目的方式数。 |
| math.copysign() | 返回由第一个参数的值和第二个参数的符号组成的浮点数。 |
| math.cos() | 返回数的余弦值。 |
| math.cosh() | 返回数的双曲余弦值。 |
| math.degrees() | 将角度从弧度转换为度。 |
| math.dist() | 返回两点(p 和 q)之间的欧几里得距离,其中 p 和 q 是该点的坐标。 |
| math.erf() | 返回数的误差函数值。 |
| math.erfc() | 返回数的互补误差函数值。 |
| math.exp() | 返回 E 的 x 次幂。 |
| math.expm1() | 返回 Ex - 1。 |
| math.fabs() | 返回数的绝对值。 |
| math.factorial() | 返回数的阶乘。 |
| math.floor() | 将数字向下舍入到最接近的整数。 |
| math.fmod() | 返回 x/y 的余数。 |
| math.frexp() | 返回指定数的尾数和指数。 |
| math.fsum() | 返回任何可迭代对象(元组,数组,列表等)中所有项的总和。 |
| math.gamma() | 返回 x 处的伽马函数值。 |
| math.gcd() | 返回两个整数的最大公约数。 |
| math.hypot() | 返回欧几里得范数。 |
| math.isclose() | 检查两个值是否彼此接近。 |
| math.isfinite() | 检查数字是否有限。 |
| math.isinf() | 检查数字是否为无穷大。 |
| math.isnan() | 检查值是否为 NaN(非数字)。 |
| math.isqrt() | 将平方根数向下舍入到最接近的整数。 |
| math.ldexp() | 返回 math.frexp() 的逆函数,即给定数字 x 和 i 的 x * (2**i)。 |
| math.lgamma() | 返回 x 的对数伽马值。 |
| math.log() | 返回数的自然对数,或以数为底的对数。 |
| math.log10() | 返回 x 的以 10 为底的对数。 |
| math.log1p() | 返回 1+x 的自然对数。 |
| math.log2() | 返回 x 的以 2 为底的对数。 |
| math.perm() | 返回从 n 个项目中不重复且有序地选择 k 个项目的方式数。 |
| math.pow() | 返回 x 的 y 次幂的值。 |
| math.prod() | 返回可迭代对象中所有元素的乘积。 |
| math.radians() | 将度数值转换为弧度。 |
| math.remainder() | 返回可以使分子完全被分母整除的最接近的值。 |
| math.sin() | 返回数的正弦值。 |
| math.sinh() | 返回数的双曲正弦值。 |
| math.sqrt() | 返回数的平方根。 |
| math.tan() | 返回数的正切值。 |
| math.tanh() | 返回数的双曲正切值。 |
| math.trunc() | 返回数字的截断整数部分。 |
数学常量
| 常量 | 描述 |
|---|---|
| math.e | 返回欧拉数(2.7182 ...)。 |
| math.inf | 返回浮点正无穷大。 |
| math.nan | 返回浮点 NaN(非数字)值。 |
| math.pi | 返回 PI(3.1415 ...)。 |
| math.tau | 返回 tau(6.2831 ...)。 |