
上QQ阅读APP看书,第一时间看更新
4.7 math
模块中的函数
math
模块中定义了用于执行各种常见数学计算的函数。下面脚本中的import
语句导入了math
模块,然后就可以通过模块名加点(.
)来使用模块中的函数:

例如,下面的代码段通过调用math
模块的sqrt
函数来计算900的平方根,该函数将结果作为浮点值返回:

类似地,下面的代码段通过调用math
模块的fabs
函数来计算-10
的绝对值,该函数将结果作为float
值返回:

下表列出了一些math
模块中的函数,如果需要查看完整列表,可以参考以下网址:https://docs.python.org/3/library/math.html。
