Python math.hypot() - Hypotenuse Function


Python math.hypot()

math.hypot(*coordinates) function returns the distance from origin to the point given by the coordinates. In case of right angled triangle, it is the length of hypotenuse.

Note: Since v3.8, N-dimensional coordinates is supported. Previous versions support only two dimensional coordinates.

Syntax

The syntax to call dist() function is

math.hypot(*coordinates)

where

ParameterRequiredDescription
coordinatesYesNumerical values representing N-dimensional coordinates.

Examples

In the following example, we find the hypotenuse of a right angled triangle, given the other two sides.

Python Program

import math

base = 4
height = 7
result = math.hypot(base, height)
print('hypot() :', result)

Output

hypot() : 8.06225774829855

In the following program, we find the distance of point (3, 5, 5, 6) from origin using hypot() function.

Python Program

import math

result = math.hypot(3, 5, 5, 6)
print('hypot() :', result)

Output

hypot() : 9.746794344808965

Summary

In this Python Examples tutorial, we learned the syntax of, and examples for math.hypot() function.