当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python Number hypot()用法及代码示例



描述

Python数法hypot()返回欧几里得范数,sqrt(x*x + y*y)。

用法

以下是语法hypot()方法 -

hypot(x, y)

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

参数

  • x- 这必须是一个数值。

  • y- 这必须是一个数值。

返回值

此方法返回欧几里得范数 sqrt(x*x + y*y)。

示例

下面的例子展示了 hypot() 方法的用法。

#!/usr/bin/python
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 Number hypot() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。