python math模块的isnan()方法,可以判断一个python的对象是否为real number,比如int、float等类型的值,如果不是,返回True,如果是则返回False。
isnan(x, /)
python源码中对isfinite()方法的介绍:
Return True if x is a NaN (not a number), and False otherwise.
参数 | 描述 |
---|---|
x | 必须参数,为real number类型。 |
Python bool类型True or False。
>>> import math
>>> math.isnan(0)
False
>>> math.isnan(2)
False
>>> math.isnan(math.nan)
True
>>> math.isnan([])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: must be real number, not list
全栈编程 / Python库(可向下滚动):
Copyright © 2022-2023 笨鸟工具 x1y1z1.com All Rights Reserved.