Python math.isnan() 方法
实例
检查值是否为 NaN:
# 导入 math 库import math# 检查某些值是否为NaNprint (math.isnan (56))print (math.isnan (-45.34))print (math.isnan (+45.34))print (math.isnan (math.inf))print (math.isnan (float("nan")))print (math.isnan (float("inf")))print (math.isnan (float("-inf")))print (math.isnan (math.nan))
定义与用法
math.isnan() 方法检查值是否为NaN(不是数字)。
如果指定的值是 NaN,则此方法返回 True,否则返回 False。
语法
math.isnan(x)
参数值
| 参数 | 描述 |
|---|---|
| x | 必填。需要检查的值 |
技术细节
| 返回值: | 一个 bool 值,True 如果值为 NaN,否则 False |
|---|---|
| Python 版本: | 3.5 |