sqrt()方法返回x的平方根(x>0)。
語(yǔ)法
以下是sqrt()方法的語(yǔ)法:
import mathmath.sqrt( x )
注意:此函數(shù)是無法直接訪問的,所以我們需要導(dǎo)入math模塊,然后需要用math的靜態(tài)對(duì)象來調(diào)用這個(gè)函數(shù)。
參數(shù)
返回值
此方法返回x的平方根,對(duì)于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)
當(dāng)我們運(yùn)行上面的程序,它會(huì)產(chǎn)生以下結(jié)果:
math.sqrt(100) : 10.0math.sqrt(7) : 2.64575131106math.sqrt(math.pi) : 1.77245385091
新聞熱點(diǎn)
疑難解答
圖片精選