sqrt()方法返回 x (x>0) 的平方根。
語法
以下是 sqrt() 方法的語法:
import math math.sqrt( x )
注:此函數無法直接訪問,所以我們需要導入 math 模組,然後用數學靜態對象調用這個函數。
參數
-
x -- 這是一個數字運算式
返回值
這個方法返回 x (x>0) 的平方根。
示例
下麵的例子顯示 sqrt()方法的使用。
#!/usr/bin/python3 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))
當我們運行上面的程式,它會產生以下結果:
math.sqrt(100) : 10.0 math.sqrt(7) : 2.6457513110645907 math.sqrt(math.pi) : 1.7724538509055159