Python Tutorial Python Advanced Python References Python Libraries

Python cmath - sqrt() Function



The Python cmath.sqrt() function returns the square root of the given complex number z. It is a function on complex plane, and has a branch cut along the negative real axis.

Syntax

cmath.sqrt(z)

Parameters

z Required. Specify a number.

Return Value

Returns the square root of z.

Example:

In the example below, sqrt() function is used to find out the square root of the given complex number.

import cmath

z1 = 2 + 2j
z2 = 2
z3 = 2j

print("cmath.sqrt(z1):", cmath.sqrt(z1))
print("cmath.sqrt(z2):", cmath.sqrt(z2))
print("cmath.sqrt(z3):", cmath.sqrt(z3))

The output of the above code will be:

cmath.sqrt(z1): (1.5537739740300374+0.6435942529055826j)
cmath.sqrt(z2): (1.4142135623730951+0j)
cmath.sqrt(z3): (1+1j)

❮ Python cMath Module