📜  Python中的数学常数

📅  最后修改于: 2022-05-13 01:55:40.499000             🧑  作者: Mango

Python中的数学常数

数学模块是Python中的标准内置模块,可用于执行数学任务。数学模块有一组方法和常量。

注意:有关详细信息,请参阅数学库函数

1. Python math.e 常量: math.e 常量返回欧拉数:2.71828182846。

例子:

# Import math Library
import math
  
# Print the value of Euler e
print (math.e)

输出:

2.718281828459045

2. Python math.pi 常量: math.pi 常量返回值 pi:3.14159265359。它被定义为圆周与直径的比值。

例子:

# Import math Library
import math
  
# Print the value of pi
print (math.pi)

输出:

3.141592653589793

3. Python math.tau 常量: math.tau 常量返回值 tau:6.283185307179586。它被定义为圆周与半径的比值。

例子:

# Import math Library
import math
  
# Print the value of tau
print (math.tau)

输出:

6.283185307179586

4. Python math.inf 常量: math.inf 常量返回正无穷大。
对于负无穷大,使用 -math.inf。inf 常量等价于 float(“inf”)。

例子:

# Import math Library
import math
  
# Print the positive infinity
print (math.inf)
  
# Print the negative infinity
print (-math.inf)

输出:

inf
-inf

5. Python math.nan 常量: math.nan 常量返回一个浮点型 nan(非数字)值。此值不是合法数字。nan 常量等价于 float(“nan”)。

例子:

# Import math Library
import math
  
# Print the value of nan
print (math.nan)

输出:

nan