math.hypot(*coordinates) returns the Euclidean norm of its arguments: sqrt(x1*x1 + x2*x2 + ...), which is the hypotenuse of a right triangle in 2D.
Unlike writing math.sqrt(x*x + y*y) by hand, math.hypot() scales intermediate values so huge inputs do not cause spurious OverflowError. Accepting zero, one, or three or more coordinates was added in Python 3.8.
math.hypot() is a function in Python's standard math module: import it with import math and call math.hypot(...), or import the name directly with from math import hypot.
Syntax
Import math and pass two coordinates (or any count in Python 3.8+).
python
import math
length = math.hypot(x, y)
norm3d = math.hypot(x, y, z)
Call
What it does
math.hypot(3, 4)
Returns 5.0.
math.hypot(2, 3, 6)
Returns 7.0 (Python 3.8+ 3D norm).
math.hypot()
Returns 0.0 (Python 3.8+).
math.hypot(float("inf"), float("nan"))
Returns inf.
To find the distance between two points p and q instead of from the origin, use math.dist() (Python 3.8+).
Function signatures
python
math.hypot(*coordinates)
# returns: float sqrt(sum(x*x for x in coordinates))
# 2 args in all versions; 0, 1, or 3+ args since Python 3.8
Parameters
Parameter
Description
*coordinates
Zero or more real numbers (int or float). Prior to Python 3.8, exactly two arguments were required.
Return Value
Return Value
Description
float
Euclidean length. Returns inf if any argument is inf or -inf (even if another is nan).
Python Examples
Example 1 — Measure 2D Right Triangles and 3D Vector Lengths
Find exact integer-triple lengths in 2D and 3D using math.hypot() (3+ args need Python 3.8+).