检查 NaN(不是数字)
在 Python 中,NaN(不是数字)由 float('nan') 表示。它用于表示无法表示为实数的值。要检查值是否为 NaN,请使用 math.isnan 函数。
示例:
import math x = float('nan') if math.isnan(x): print("x is NaN") else: print("x is not NaN")
输出:
x is NaN
以上是如何在 Python 中检查 NaN(不是数字)?的详细内容。更多信息请关注PHP中文网其他相关文章!