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字符串