all Python 3cmathfunction
cmath.polar()
polar coordinates
Converts a complex number to polar coordinates: returns a (modulus, angle) tuple of two floats.
Syntax
r, phi = cmath.polar(z)
It returns plain floats, not complex: polar(z) is (abs(z), phase(z)). The angle is in radians and in the range (-π, π], so a round trip through rect may give a different angle back: rect(1, 3π/2) turns into an angle of about -π/2. Use math.degrees for degrees.
Examples
import cmath
print(cmath.polar(1 + 1j)) # → (1.4142135623730951, 0.7853981633974483)
print(cmath.polar(-2)) # → (2.0, 3.141592653589793)
import cmath
import math
r, phi = cmath.polar(cmath.rect(1, 3 * math.pi / 2))
print(round(math.degrees(phi))) # → -90
See also
Open in the full glossarydocs.python.orgReport an inaccuracy