当前位置: 首页 > 文档资料 > Python 中文教程 >

hypot(x, y)

优质
小牛编辑
115浏览
2023-12-01

描述 (Description)

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

语法 (Syntax)

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

hypot(x, y)

Note - 此函数不能直接访问,因此我们需要导入数学模块,然后我们需要使用数学静态对象调用此函数。

参数 (Parameters)

  • x - 必须是数值。

  • y - 必须是数值。

返回值 (Return Value)

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

例子 (Example)

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