Base de conocimientosCentro de exámenes
ESEspañol
Elegir idioma13

CKTIS / Python

math.nan

Proporciona el valor float especial que indica la ausencia de resultado numérico.

Versión: Python 3.14; repository image, production runtime not attested

Sintaxis

math.nan

Proporciona el valor float especial que indica la ausencia de resultado numérico.

Incluso comparar math.nan consigo mismo mediante == da False.

Para filtrar mediciones, math.isnan da True para NaN y False para el infinito.

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

Ejemplos

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

Resultado

False
True

Para filtrar mediciones, math.isnan da True para NaN y False para el infinito.

Fuentes