Python Glossary Русский

all Python 3cmathfunction

cmath.phase()

polar coordinates

The argument (angle) of a complex number in radians, in the range from -π to π. The same as math.atan2(z.imag, z.real).

Syntax

cmath.phase(z)

The angle lies in (-π, π], not in [0, 2π): a point just below the negative real axis gives almost -π, not almost π. On the axis itself the sign of zero decides: phase(complex(-1, 0.0)) = π, phase(complex(-1, -0.0)) = -π. For degrees or a range of [0, 360), convert with math.degrees and take % 360.

Examples

import cmath
print(cmath.phase(1j))  # → 1.5707963267948966
print(cmath.phase(complex(-1, 0.0)), cmath.phase(complex(-1, -0.0)))  # → 3.141592653589793 -3.141592653589793
import cmath
import math
angle = math.degrees(cmath.phase(-1j)) % 360
print(angle)  # → 270.0

See also

Open in the full glossarydocs.python.orgReport an inaccuracy