math.hypot() 方法是 Python 的 math 模块中的一个函数,用于计算欧几里得范数(Euclidean norm)。

以下是 math.hypot() 方法的基本语法:
math.hypot(x, y)

  •  x 和 y: 两个数值。


返回值是欧几里得范数,即平面上从原点到点 (x, y) 的直线距离。

以下是一些示例:
import math

# 计算欧几里得范数,例如 hypot(3, 4)
result1 = math.hypot(3, 4)
print(result1)  # 输出 5.0

# 计算欧几里得范数,例如 hypot(1, 1)
result2 = math.hypot(1, 1)
print(result2)  # 输出 1.4142135623730951

# 计算欧几里得范数,例如 hypot(-2, -2)
result3 = math.hypot(-2, -2)
print(result3)  # 输出 2.8284271247461903

在这个例子中,math.hypot() 函数分别计算了点 (3, 4)、(1, 1) 和 (-2, -2) 到原点的欧几里得范数。这个函数在平面几何和三维空间中的向量运算中经常用于计算距离。


转载请注明出处:http://www.zyzy.cn/article/detail/374/Python3