Python數字hypot()方法

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

語法

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

hypot(x, y)

注意 - 此函數不能直接訪問,需要導入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.60555127546
hypot(-3, 3) :  4.24264068712
hypot(0, 2) :  2.0

上一篇: Python數字 下一篇: Python字串