#import the cmath module
import cmath

print(cmath.nan)

The cmath(complex math) module defines the nan attribute which represents the NaN value. In the context of complex numbers, NaN(not a Number) values are used to represent complex arithmetic operations that yield an undefined result.

cmath.nan
import cmath

print(cmath.nan + 2)
print(-cmath.nan)