sqrt()方法返回x的平方根(x>0)。
語法
以下是sqrt()方法的語法:
import mathmath.sqrt( x )
注意:此函數(shù)是無法直接訪問的,所以我們需要導入math模塊,然后需要用math的靜態(tài)對象來調用這個函數(shù)。
參數(shù)
返回值
此方法返回x的平方根,對于x>0。
例子
下面的例子顯示了sqrt()方法的使用。
#!/usr/bin/pythonimport math # This will import math moduleprint "math.sqrt(100) : ", math.sqrt(100)print "math.sqrt(7) : ", math.sqrt(7)print "math.sqrt(math.pi) : ", math.sqrt(math.pi)
當我們運行上面的程序,它會產生以下結果:
math.sqrt(100) : 10.0math.sqrt(7) : 2.64575131106math.sqrt(math.pi) : 1.77245385091
新聞熱點
疑難解答
圖片精選