Home >>Python cmath Module >Python cmath.sqrt() Method

Python cmath.sqrt() Method

Python cmath.sqrt() Method

Python method cmath.sqrt() returns a complex number with the square root.

Syntax:
cmath.sqrt(x)

Parameter Values

Parameter Description
x It is a required parameter to find the square root of a number. It returns a ValueError If the number is less than 0. It returns a TypeError if the value is not a number
Here is an Example of Python cmath.sqrt() Method:

import cmath  
print (cmath.sqrt(1 + 2j))
print (cmath.sqrt(12))

Output:
(1.272019649514069+0.7861513777574233j)
(3.4641016151377544+0j)
Example 2:

import cmath  
print (cmath.sqrt(3 + 5j))
print (cmath.sqrt(8))

Output:
(2.101303392521568+1.189737764140758j)
(2.8284271247461903+0j)