Python - Numeric Complex Numbers


Python complex literals are written as real part+imaginary part.

The imaginary part is terminated with a j or J.

The real part is technically optional, so the imaginary part may appear on its own.

Internally, complex numbers are implemented as pairs of floating-point numbers, but all numeric operations perform complex math when applied to complex numbers.

Complex numbers may also be created with the complex(real, imag) built-in call.

Complex numbers are a core object type in Python.

They are used in engineering and science applications.

Complex numbers are represented as two floating-point numbers: the real and imaginary parts.

You code them by adding a j or J suffix to the imaginary part.

We can write complex numbers with a nonzero real part by adding the two parts with a +.

For example, the complex number with a real part of 2 and an imaginary part of -3 is written 2 + -3j.

Here are some examples of complex math:


print( 1j * 1J )
print( 2 + 1j * 3 ) 
print( (2 + 1j) * 3 )


Complex numbers can extract their parts as attributes, supports all the usual mathematical expressions.

They can be processed with tools in the standard cmath module.

cmath module is the complex version of the standard math module.