The builtin math module defines the attribute nan which is used to represent a Not-a-Number (NaN) value.

We get a NaN value when we perform an undefined arithmetic operation such as division by 0, or finding the square root of negative numbers.

ExampleEdit & Run
#import math module
import math

#print the nan value
print(math.nan)
Output:
nan [Finished in 0.022952676052227616s]
Syntax:
math.nan

The math.nan value is a floating point value  which is equivalent to float("nan")

ExampleEdit & Run
import math

print(type(math.nan))
print(float("nan"))
Output:
<class 'float'> nan [Finished in 0.028383369091898203s]

The math.isnan() function returns True if the argument given has a value of nan.

ExampleEdit & Run
import math

print(math.isnan(math.nan))
print(math.isnan(float('nan')))
Output:
True True [Finished in 0.020550803979858756s]

Some  things to note

  1. Two NaN values are never equal to each other.
  2. Any operation with a NaN value always returns NaN
  3. There is no negative NaN.
ExampleEdit & Run
import math

print(math.nan == math.nan)
print(float('nan') == float('nan'))
print(math.nan + 7)
print(-math.nan)
Output:
False False nan nan [Finished in 0.024439095985144377s]