Find square root of negative number using python


Find square root of negative number using python

đź“‹ Table Of Content

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.

Example:

import cmath

number = -5

negative_sq_val = cmath.sqrt(number)

print(negative_sq_val)

Output:

2.23606797749979j

Here, in this example, we have imported the cmath module and then passed the negative number to the sqrt() method.

The cmath.sqrt() method performs the mathematical operations to find the square root and returns the number.


Other Articles You'll Also Like:

Square a number in Python (3 ways)