CKTIS / Python
math.isnan
Liefert einen booleschen Wert dafür, ob das Argument NaN ist.
Version: Python 3.14; repository image, production runtime not attested
Syntax
math.isnan(x, /)Liefert einen booleschen Wert dafür, ob das Argument NaN ist.
Aus dem Text "nan" entsteht beim Umwandeln in float NaN, also True. Positive Unendlichkeit ist eine andere Kategorie und ergibt False.
Ein Vergleich per == würde nicht einmal denselben NaN-Wert erkennen.
import math
x = float("nan")
assert x != x and math.isnan(x)
assert not math.isnan(math.inf) and not math.isnan(0.0)
Beispiele
import math
print(math.isnan(float("nan")))
print(math.isnan(math.inf))
Ergebnis
True False
Ein Vergleich per == würde nicht einmal denselben NaN-Wert erkennen.