Base di conoscenzaCentro esami
ITItaliano
Scegli la lingua13

CKTIS / Python

math.nan

Fornisce il valore float speciale che segnala l’assenza di un risultato numerico.

Versione: Python 3.14; repository image, production runtime not attested

Sintassi

math.nan

Fornisce il valore float speciale che segnala l’assenza di un risultato numerico.

Anche confrontare math.nan con se stesso tramite == dà False.

Per filtrare misure, math.isnan dà True per NaN e False per l’infinito.

import math
assert isinstance(math.nan, float) and math.nan != math.nan
assert math.isnan(math.nan) and not math.isinf(math.nan)

Esempi

import math
print(math.nan == math.nan)
print(math.isnan(math.nan))

Risultato

False
True

Per filtrare misure, math.isnan dà True per NaN e False per l’infinito.

Fonti