Python math 模块简介
python 中的 math 模块提供了一系列数学函数和常量,用于进行数学运算。
常量
math 模块包含一些有用的 数学常量:
-
math.e: 自然对数的底数 (e ≈ 2.718) -
math.pi: 圆周率 (π ≈ 3.14159) -
math.tau: 圆周率的两倍 (≈ 6.28318)
三角函数
math 模块提供了各种三角函数:
-
math.sin(x): 正弦 -
math.cos(x): 余弦 -
math.tan(x): 正切 -
math.asin(x): 反正弦 -
math.acos(x): 反余弦 -
math.atan(x): 反正切
双曲函数
math 模块还提供了一系列双曲函数:
-
math.sinh(x): 双曲正弦 -
math.cosh(x): 双曲余弦 -
math.tanh(x): 双曲正切 -
math.asinh(x): 反双曲正弦 -
math.acosh(x): 反双曲余弦 -
math.atanh(x): 反双曲反正切
其他函数
math 模块还提供了其他有用的函数:
立即学习“Python免费学习笔记(深入)”;
-
math.sqrt(x): 平方根 -
math.fabs(x): 绝对值 -
math.ceil(x): 向上取整 -
math.floor(x): 向下取整 -
math.exp(x): 自然指数 -
math.log(x): 自然对数 -
math.log10(x): 以 10 为底的对数











