Python check NaN values with and without using packages - Devsheet

PHOTO EMBED

Sat Mar 18 2023 05:50:18 GMT+0000 (Coordinated Universal Time)

Saved by @xvmodvx #python

# 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
content_copyCOPY

https://devsheet.com/code-snippet/python-check-nan-values-with-and-without-using-packages/