The math.sqrt() function calculates the square root of a number.

Syntax:
math.sqrt(x)
copy

Where, is  number for which the square root should be calculated.

The function returns   square root of the given number  as a a floating point value.

ExampleEdit & Run
import math
print(math.sqrt(4))
print(math.sqrt(7))
print(math.sqrt(16))
print(math.sqrt(30))
print(math.sqrt(625))
copy
Output:
2.0 2.6457513110645907 4.0 5.477225575051661 25.0 [Finished in 0.010845648124814034s]

If the given number is less than 0, a ValueError is raised.

ExampleEdit & Run
import math

print(math.sqrt(-2))
copy
Output:
Traceback (most recent call last):   File "<string>", line 3, in <module> ValueError: math domain error [Finished in 0.010235955938696861s]