在本文中,我们将学习Python标准库中math模块中可用的特殊函数和常量。
在这里,我们将讨论一些常量-
pi
Ë
信息
楠
头
还有一些功能,例如
伽玛
伊辛夫
伊斯南
isfinite()
erf()
让我们讨论常量及其各自的值-
pi | 3.141592….. |
Ë | 2.718281 ...... |
信息 | 6.283185 ...... |
南 | <无限> |
头 | <不是数字> |
现在让我们讨论一些特殊功能及其实现-
Gamma-返回gamma(n)的值
Isinf-检查函数的值是否为无穷大。
Isnan-检查返回值是否是数字。
Isfinite-如果值既不是无穷大也不是nan false,则返回True
Erf-返回x的误差函数。
现在让我们看一个例子-
import math num=10 print (math.gamma(num)) if (math.isnan(math.nan)): print ("The number is not a number") else : print ("The number is a number") if (math.isinf(math.inf)): print ("The number is positive infinity") else : print ("The number is not positive infinity") print(math.isfinite(math.inf))
输出结果
362880.0 The number is not a number The number is positive infinity False
在本文中,我们了解了Python中的数学函数-特殊函数和常量。