Python ``hypot()`` 函数使用教程


发布日期 : 2019-04-20 09:46:11 UTC

访问量: 10 次浏览

Python 3 – 数字 hypot() 方法

描述

方法hypot()返回欧几里德范数,即 sqrt(xx + yy)。这是从原点到点(x,y)的向量长度。

语法

下面是hypot()方法的语法 −

hypot(x, y)

注意
− 此函数无法直接访问,因此我们需要导入 math 模块,然后使用 math 静态对象调用此函数。

参数

  • y− 这必须是数字值。
  • x− 这必须是数字值。

返回值

此方法返回欧几里德范数,即 sqrt(xx + yy)。

示例

以下示例展示了 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