Checking for NaN (Not a Number)
In Python, NaN (not a number) is represented by float('nan'). It's used to represent values that cannot be represented as real numbers. To check if a value is NaN, utilize the math.isnan function.
Example:
import math x = float('nan') if math.isnan(x): print("x is NaN") else: print("x is not NaN")
Output:
x is NaN
The above is the detailed content of How to Check for NaN (Not a Number) in Python?. For more information, please follow other related articles on the PHP Chinese website!