python math.isinf() 方法
python math.isinf() 方法判断 x 是否是无穷大,如果 x 是正或负无穷大,则返回 true ,否则返回 false 。
python 版本:2.6
语法math.isinf() 方法语法如下:
math.isinf(x)
参数说明:
- x -- 必需,数字。如果 x 不是一个数字,返回 typeerror。
返回一个布尔值,如果 x 是正或负无穷大,则返回 true ,否则返回 false 。
实例以下实例检查数字是否是无穷大:
实例
# 导入 math 包
import math
# 检查数字是否是无穷大
print(math.isinf(56))
print(math.isinf(-45.34))
print(math.isinf(+45.34))
print(math.isinf(math.inf))
print(math.isinf(float("nan")))
print(math.isinf(float("inf")))
print(math.isinf(float("-inf")))
print(math.isinf(-math.inf))
import math
# 检查数字是否是无穷大
print(math.isinf(56))
print(math.isinf(-45.34))
print(math.isinf(+45.34))
print(math.isinf(math.inf))
print(math.isinf(float("nan")))
print(math.isinf(float("inf")))
print(math.isinf(float("-inf")))
print(math.isinf(-math.inf))
输出结果:
false false false true false true true true
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!