Python3 hypot() 函數(shù)

Python3 數(shù)字 Python3 數(shù)字


描述

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


語法

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

import math

math.hypot(x, y)

注意:hypot()是不能直接訪問的,需要導(dǎo)入 math 模塊,然后通過 math 靜態(tài)對象調(diào)用該方法。


參數(shù)

  • x -- 一個數(shù)值。
  • y -- 一個數(shù)值。

返回值

返回歐幾里德范數(shù) 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))

以上實例運行后輸出結(jié)果為:

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

Python3 數(shù)字 Python3 數(shù)字