Latest web development tutorials

Python3 hypot() 函數

Python3 數字 Python3數字


描述

hypot()返回歐幾里德範數sqrt(x*x + y*y)。


語法

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

import math

math.hypot(x, y)

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


參數

  • x -- 一個數值。
  • y -- 一個數值。

返回值

返回歐幾里德範數sqrt(x*x + y*y)。


實例

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

#!/usr/bin/python3
import math

print ("hypot(3, 2) : ",  math.hypot(3, 2))
print ("hypot(-3, 3) : ",  math.hypot(-3, 3))
print ("hypot(0, 2) : ",  math.hypot(0, 2))

以上實例運行後輸出結果為:

hypot(3, 2) :  3.605551275463989
hypot(-3, 3) :  4.242640687119285
hypot(0, 2) :  2.0

Python3 數字 Python3數字