In this article, we will learn how to find the square root of a negative number using python.
To find the square root of a negative number we have to use complex numbers. In python, we have the
cmath that provides us with various mathematical functions to work with complex numbers.
Square root of a negative number in Python
To work with complex numbers we can use the
cmath library of python. And to get the square of a negative number we can use the
cmath.sqrt() method from cmath library.
import cmath number = -5 negative_sq_val = cmath.sqrt(number) print(negative_sq_val)
Here, in this example, we have imported the cmath module and then passed the negative number to the
cmath.sqrt() method performs the mathematical operations to find the square root and returns the number.
Other Articles You’ll Also Like: