Python sqrt() 函數(shù)
python sqrt() 函數(shù)
sqrt() 方法返回數(shù)字x的平方根。
1. 語法
以下是 sqrt() 方法的語法:
import math math.sqrt( x )
注意:sqrt()是不能直接訪問的,需要導(dǎo)入 math 模塊,通過靜態(tài)對象調(diào)用該方法。
2. 參數(shù)
- x -- 數(shù)值表達式。
3. 返回值
返回數(shù)字x的平方根。
4. 實例
以下展示了使用 sqrt() 方法的實例:
#!/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)
以上實例運行后輸出結(jié)果為:
math.sqrt(100) : 10.0 math.sqrt(7) : 2.64575131106 math.sqrt(math.pi) : 1.77245385091