11. math库函数
一、math库介绍
内置数学类函数库,math库不支持复数类型,仅支持整数和浮点数运算。
math库一共提供了:
4个数字常数
44个函数,分为4类:
16个数值表示函数
8个幂对数函数
16个三角对数函数
4个高等特殊函数
库中函数不能直接使用,需使用保留字import引用:
import math
math.<函数名>(...)
或者
from math import <函数名>
<函数名>(...)
3.2 math库的数值表示函数(16个)
3.3 math库的幂对数函数(8个)
3.4 math库的三角运算函数(16个)
3.5 math库的高等特殊函数(4个)
四:举例
# math_constants.pyimportmathprint(' π: {:.30f}'.format(math.pi))print(' e: {:.30f}'.format(math.e))print('nan: {:.30f}'.format(math.nan))print('inf: {:.30f}'.format(math.inf))
π 和 e 的精度仅受平台浮点C语言库限制。
$ python3 math_constants.py
π: 3.141592653589793115997963468544
e: 2.718281828459045090795598298428
nan: nan
inf: inf
其他一些具体详细操作:https://zhuanlan.zhihu.com/p/107101718