Python Glossary Русский

all Python 3mathterm

math.hypot

geometry

The Euclidean distance from the origin. Python 3.8+: any number of arguments.

Syntax

math.hypot(*coordinates)

hypot() does not compute the formula literally — it rescales the intermediate values, so it still gives a sane answer where sqrt(x*x + y*y) would overflow or lose significant digits. To measure the distance between two points, do not subtract the coordinates by hand: math.dist(p, q) does it for you. Accepting an arbitrary number of arguments arrived only in 3.8; on 3.7 and older hypot() takes exactly two.

Examples

import math
print(math.hypot(3, 4))      # → 5.0
print(math.hypot(5, 12))     # → 13.0
print(math.hypot(1, 1))      # → 1.41421...
print(math.hypot(0, 5))      # → 5.0
print(math.hypot(1, 1, 1))   # → 1.732... (3D)
print(math.hypot(3, 4, 0))   # → 5.0

See also

Open in the full glossarydocs.python.orgReport an inaccuracy