Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

math.nan

Represents a floating-point value whose numeric result is undefined.

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

Syntax

math.nan

Represents a floating-point value whose numeric result is undefined.

A NaN does not compare equal to itself; use the dedicated predicate when filtering measurements.

Use NaN to carry a nonnumeric or missing floating-point result. Even a comparison of this value with itself using equality is false. math.isnan returns true for it and false for infinity. Testing for equality with the NaN constant cannot detect another NaN.

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

Examples

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

Result

False
True

Use NaN to carry a nonnumeric or missing floating-point result. Even a comparison of this value with itself using equality is false. math.isnan returns true for it and false for infinity. Testing for equality with the NaN constant cannot detect another NaN.

Sources