初步格式
点击上传
X
math.isinf()方法是数学模块的库方法,用于检查数字是否为无穷大(正数或负数),它接受数字并在给定数字为正或负无穷大时返回True,否则返回False。
它的语法 math.isinf() 方法:
math.isinf(n)
Parameter(s): n –必须检查是否为无穷大的数字。
返回值: bool –返回布尔值(“ True”或“ False”)。
示例
Input:
a = 10
b = float('inf')
# 函数调用
print(math.isinf(a))
print(math.isinf(b))
Output:
False
True# python代码演示示例
# math.isinf() method
# 导入数学模块
import math
# math.isinf() method test on finite value
print(math.isinf(10))
print(math.isinf(0))
print(math.isinf(10.23))
print(math.isinf(0.0))
# math.isinf() method test on infinite value
print(math.isinf(float('inf')))
print(math.isinf(float('-inf')))
print(math.isinf(float('nan')))输出结果
False False False True True False