Python Glossary Русский

all Python 3Numbers & mathfunction

complex.conjugate

complex

Return the complex conjugate: flip the sign of the imaginary part (a+bj → a−bj).

Syntax

z.conjugate()

Watch the parentheses: real and imag are attributes, but conjugate is a method, so dropping the () hands you a bound method object instead of a number. int and float carry the same method (it returns the value unchanged), so numeric code can call it without checking the type first. z * z.conjugate() is the squared modulus, yet it stays a complex with a zero imaginary part — use abs(z) ** 2 or .real when you want a plain float.

Examples

print((3 + 4j).conjugate())                 # → (3-4j)
print(complex(2, -5).conjugate())           # → (2+5j)
print((3 + 4j) * (3 + 4j).conjugate())      # → (25+0j)
print((3 + 4j).conjugate().imag)            # → -4.0
print((2 - 3j).conjugate().conjugate())     # → (2-3j)
print((7 + 0j).conjugate())                 # → (7-0j)

See also

Open in the full glossarydocs.python.orgReport an inaccuracy