What is math.isnan() in python?
The math module in Python provides access to mathematical functions and constants. math.isnan() checks whether a value is a number or not.
Usage
Suppose you want to validate records that specify the trends in inflation. math.isnan() will be used to check if the values entered are numbers or not. This mechanism is used largely in validating systems.
Syntax
math.isnan(x)
Arguments
x: The value to be checked.
This parameter is required.
Return value
The function returns a Boolean value of true if the value is not a number, and false if it is a number.
Code
#import libraryimport math#initialize variablesa = 3b = -5.6c = math.infd = 9932.435e = +57f = 0.00004g = math.nan#Check whether variables are NaNprint(a, ':', math.isnan(a))print(b, ':', math.isnan(b))print(c, ':', math.isnan(c))print(d, ':', math.isnan(d))print(e, ':', math.isnan(e))print(f, ':', math.isnan(f))print(g, ':', math.isnan(g))