Python complex() Function

The complex() function returns a complex number by specifying a real number and an imaginary number. Complex numbers in python are written using the ‘j’ suffix, which represents the imaginary part.

For example, ‘3+4j’ is a complex number where 3 is a real part and 4 is the imaginary part.

Syntax : complex(real, imaginary)

Parameter values:

real : Required. A number representing the real part of the complex number. Default 0

imaginary : Optional. A number representing the imaginary part of complex number. Default 0

Creating Complex Numbers

z1 = complex(3, 4)
z2 = 3 + 4j
Built-in Functions for Complex Numbers

Python’s standard library includes the ‘cmath’ module, which provides mathematical functions for complex numbers.

1.Absolute Value and Phase

z = 1 + 1j
abs_z = abs(z)
phase_z = cmath.phase(z)
polar_z = cmath.polar(z)

2.Exponential and Logarithmic Function

exp_z = cmath.exp(z)
log_z = cmath.log(z)
log10_z = cmath.log10(z)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top