Python3 hypot()函式

2019-10-16 23:12:19
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