Python3 sqrt() 函數

Python3 數字 Python3 數字


描述

sqrt() 方法返回數字x的平方根。


語法

以下是 sqrt() 方法的語法:

import math

math.sqrt( x )

注意:sqrt()是不能直接訪問的,需要導入 math 模組,通過靜態對象調用該方法。


參數

  • x -- 數值運算式。

返回值

返回數字x的平方根。

實例

以下展示了使用 sqrt() 方法的實例:

實例

#!/usr/bin/python3 import math # 導入 math 模組 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

Python3 數字 Python3 數字