Check if number is NaN (Not a number)

import math

def is_nan(num):
    return math.isnan(num)

# Test
print(is_nan(float('nan')))  # True
print(is_nan(5))              # False
print(is_nan(float('inf')))  # False

Leave a Reply

Your email address will not be published. Required fields are marked *