The math.isnan()
function is used to determine whether or not a given value is Not a Number (NaN).
math.isnan(x)
Where, x
is the value which we want to check whether it is N
ot a N
umber.
The return value of this function will be either True
or False
, depending on whether or not the given argument is a NaN.
What do we mean by 'Not a Number'?
Not a Number (NaN) is a special value used to represent any computation result which is undefined or meaningless. It is also known as an undefined number. This value can be returned when the result of a mathematical operation is undefined.For example
- Division by zero, such as 1/0.
- Calculating the square root of a negative number
- Attempting to get logarithm of a negative number.
In Python, NaN is represented as float('nan')