The math.sqrt()
function calculates the square root of a number.
math.sqrt(x)
Where, x
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.
import math
print(math.sqrt(4))
print(math.sqrt(7))
print(math.sqrt(16))
print(math.sqrt(30))
print(math.sqrt(625))
If the given number is less than 0, a ValueError
is raised.
import math
print(math.sqrt(-2))