主要内容 #
- math包的功能介绍
- math包的基本常数
- math包的常用函数:exp() log() pow() sqrt()
1. math包的功能介绍 #
math包主要提供了许多对于浮点数的数学运算函数。 math包里的函数仅用于实数范围,复数范围的计算请使用用cmath包2. math包的基本常数 #
math包的基本常数如下:import math print("math.pi = ", math.pi) print("math.e = ", math.e) print("math.inf = ", math.inf) print("math.nan = ", math.nan)
3. math包的常用函数:exp() log() pow() sqrt() #
import math print(math.exp(-3)) # x可以是正数或负数,等价于print(math.e**(-3)) print(math.exp(math.pi+1)) # x可以是表达式
import math print(math.log(math.e)) # 默认底数为e print(math.log(100, 10)) # base设置为10 print(math.log(math.pi+1)) # 参数可以是表达式
import math print(math.pow(10, 3)) # 等价于print(10**3) print(math.pow(math.pi, math.e)) # x,y可以是表达式
import math print(math.sqrt(100)) print(math.sqrt(math.pi+1)) # x可以是表达式