What is math.sqrt() in Python?

The sqrt() function in Pythonreturns the square root of a non-negative number.

Figure 1 shows the mathematical representation of the sqrt() function.

Figure 1: Mathematical representation of the sqrt() function

The math module is required to use this function.

Syntax

sqrt(number)

Parameter

sqrt() requires a non-negative number as a parameter.

Return value

sqrt() returns the square root of the number sent as a parameter.

Example

import math
#perfect square root
print "sqrt(4):", math.sqrt(4)
print "sqrt(0):", math.sqrt(0)
#simple number
print "sqrt(5):", math.sqrt(5)
print "sqrt(4.5):", math.sqrt(4.5)

Free Resources