Python sqrt() Function

Python 数字Python Numbers


Description

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


Syntax

The syntax of the sqrt() method is as follows:

import math

math.sqrt( x )

Note:sqrt() cannot be accessed directly; you need to import the math module and call this method via a static object.


Parameters

  • x -- A numeric expression.

Return Value

Returns the square root of 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)

The output after running the above example is:

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

Python 数字Python Numbers

Other Extensions