Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

Python cmath.nanj Constant



The Python cmath.nanj Constant returns a complex NaN (Not a Number). This value has 0 as real part, and NaN as the imaginary part. The nanj constant is equivalent to complex (0.0, float("nan")).

NaN is a floating-point value represented by the float('nan') object in Python.

Syntax

Following is the basic syntax of the cmath.nanj Constant −

cmath.nanj

Return Value

This Constant returns the complex NaN value.

Example 1

Below example illustrates the usage of the cmath.nanj constant.

import cmath
value = cmath.nanj
print(value)

Output

The output obtained is as follows −

nanj

Example 2

Here, we are calculating arithmetic operations using the cmath.nanj constant.

import cmath
print(cmath.nanj + 2)     #add
print(cmath.nanj - 4)     #sub
print(cmath.nanj ** 9)    #pow
print(cmath.nanj / 1000)  #div

Output

When we run the above code, it produces the following result −

(2+nanj)
(-4+nanj)
(nan+nanj)
(nan+nanj)
python_modules.htm
Advertisements