Facebook Page Twitter Page LinkedIn Page
× Python Tutorial Python Advanced Python Resources Python Libraries


The Python cmath.rect() function is used to convert a complex number from polar coordinates to rectangular coordinates. The function returns (x, y) which is a rectangular representation of (r, θ). rect(r, θ) is equivalent to (r*cos(θ), r*sin(θ)) = (x, y).

Syntax

cmath.rect(r, θ)

Parameters

r Required. Specify the modulus of a complex number.
θ Required. Specify the phase of a complex number.

Return Value

Returns the representation of a complex number in rectangular coordinates.

Example:

In the below example, rect() function is used to convert a given complex number from polar coordinates to rectangular coordinates.

import cmath

r = 5
theta = cmath.pi/3

print(cmath.rect(r, theta))

The output of the above code will be:

(2.5000000000000004+4.330127018922193j)

❮ Python cMath Module