# By comparing itself def is_nan(val): return val != val nan_value = float("nan") print(is_nan(nan_value)) # -> True #Using math.isnan(Import math before using math.isnan) import math nan_value = float("NaN") check_nan = math.isnan(nan_value) print(check_nan) # -> True
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter