Python isinf

Python isinf 函数用于检查给定值是否为无穷大。如果它是一个无穷大的数字,则 math.isinf 返回 True,否则返回 False,其语法如下所示。

math.isinf(value)

Python isinf 示例

在此示例中,我们将 isinf 函数应用于正数和负数的数值和十进制值。我们还在此函数中使用了 Python math.pi。

import math
 
print(math.isinf(10))
 
print(math.isinf(0.00))
 
print(math.isinf(-200))
 
print(math.isinf(-4.0002))
 
print(math.isinf(math.pi))
False
False
False
False
False

在此 数学函数 中,我们将 infinity 和 NaN(非数字)值作为 isinf 函数的参数传递。

import math
 
print(math.isinf(0/1))
 
print(math.isinf(0.00/1))
 
print(math.isinf(float('NaN')))
 
print(math.isinf(float('inf')))
 
print(math.isinf(float('-inf')))
isinf Function Example