Python3 hypot()函數

hypot() 方法返回歐幾裏得範數,sqrt(x*x + y*y). 這是向量從原點到點(x,y)的長度

語法

以下是 hypot()方法的語法:
hypot(x, y)
注:此功能直接是無法訪問的,所以我們需要導入 math 模組,然後我們需要用 math 靜態對象調用這個函數。

參數

  • x -- 這必須是一個數值

  • y -- 這必須是一個數值

返回值

hypot() 方法返回歐幾裏得範數, 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.60555127546
hypot(-3, 3) :  4.24264068712
hypot(0, 2) :  2.0

上一篇: Python3迴圈 下一篇: Python3數字