Python math.sqrt() method “returns the square root of any number.”
x: It is any number such that x>=0. The sqrt() function takes a number as an argument.
It returns the square root of a number argument.
Example 1: How to Use math.sqrt() Method
Import math module to work with mathematical operations in Python.
import math print(math.sqrt(81))
It is the best way to find the square root of any number.
Example 2: Passing positive argument
Another way will give us the same output, but the number must be positive, not negative, and not complex.
num = 49 sq_root = num ** 0.5 print(sq_root)
Example 3: Passing a complex number
To calculate a square root of a complex number in Python, use the cmath module. To use the cmath module, you must import it and then use its sqrt() function.
import cmath print(cmath.sqrt(1 + 2j))