Latest web development tutorials

Python sqrt () function

Python figures Python figures


description

sqrt () method returns the square root of the number x.


grammar

The following is the syntax sqrt () method:

import math

math.sqrt( x )

Note: sqrt () is not directly accessible, you need to import math module, invoke the method through static object.


parameter

  • x - numeric expression.

return value

Returns the square root of the number x.

Examples

The following shows an example of using the sqrt () method:

#!/usr/bin/python
import math   # This will import math module

print "math.sqrt(100) : ", math.sqrt(100)
print "math.sqrt(7) : ", math.sqrt(7)
print "math.sqrt(math.pi) : ", math.sqrt(math.pi)

After running the above example output is:

math.sqrt(100) :  10.0
math.sqrt(7) :  2.64575131106
math.sqrt(math.pi) :  1.77245385091

Python figures Python figures