Python数学常量

Python数学常量:

  math.pi:π

  math.e:自然常数 e

程序:

import math

# 查看 pi 和 e 的值
print(math.pi)
# 3.141592653589793
print(math.e)
# 2.718281828459045


# 计算圆的面积
r = 2
print(math.pi * r ** 2)
# 12.566370614359172

# lg 函数中求值

a = math.e

b = math.e ** 5

print("ln(a)的值为:",math.log(a))
# ln(a)的值为: 1.0

print("ln(b)的值为:",math.log(b))
# ln(b)的值为: 5.0

2020-02-06