Python Tutorial Python Advanced Python References Python Libraries

Python cmath - polar() Function



The Python cmath.polar() function returns the representation of x in polar coordinates. The function returns (r, θ) which is a polar representation of x, where r is the modulus of x and θ is the phase of x. polar(x) is equivalent to (abs(x), phase(x)).

Syntax

cmath.polar(x)

Parameters

x Required. Specify the number.

Return Value

Returns the representation of x in polar coordinates.

Example:

In the example below, polar() function is used to representation the given complex number in polar coordinates.

import cmath

x1 = 3 + 4j
x2 = 3 - 4j
x3 = -3 + 4j
x4 = -3 - 4j

print("cmath.polar(3 + 4j) =", cmath.polar(x1))
print("cmath.polar(3 - 4j) =", cmath.polar(x2))
print("cmath.polar(-3 + 4j) =", cmath.polar(x3))
print("cmath.polar(-3 - 4j) =", cmath.polar(x4))

The output of the above code will be:

cmath.polar(3 + 4j) = (5.0, 0.9272952180016122)
cmath.polar(3 - 4j) = (5.0, -0.9272952180016122)
cmath.polar(-3 + 4j) = (5.0, 2.214297435588181)
cmath.polar(-3 - 4j) = (5.0, -2.214297435588181)

❮ Python cMath Module