HiveBrain v1.2.0
Get Started
← Back to all entries
snippetpythonCritical

How to check for NaN values

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
howvaluescheckfornan

Problem

float('nan') represents NaN (not a number). But how do I check for it?

Solution

Use math.isnan:

>>> import math
>>> x = float('nan')
>>> math.isnan(x)
True

Code Snippets

>>> import math
>>> x = float('nan')
>>> math.isnan(x)
True

Context

Stack Overflow Q#944700, score: 2210

Revisions (0)

No revisions yet.