YouTip LogoYouTip

Func Number Hypot

Python hypot() Function | Rookie Tutorial

Python hypot() Function | Rookie Tutorial

Rookie Tutorial -- Learning not just technology, but dreams!

Python Basic Tutorials

Python Advanced Tutorials

Python hypot() Function

The hypot() function in Python returns the Euclidean norm, which is equivalent to the square root of the sum of squares of its arguments.

It is commonly used to calculate the length of the hypotenuse of a right triangle given the lengths of the other two sides.

Syntax

math.hypot(x, y)

Parameters

  • x: A number representing one side of the right triangle.
  • y: A number representing the other side of the right triangle.

Returns

Returns the Euclidean distance from the origin to the point (x, y), i.e., √(x² + y²).

Example

import math

print(math.hypot(3, 4))  # Output: 5.0
print(math.hypot(5, 12)) # Output: 13.0
print(math.hypot(8, 15)) # Output: 17.0

Notes

  • The function is part of the math module and must be imported before use.
  • It handles negative values correctly; the sign of the input does not affect the result.
  • For higher-dimensional cases, math.hypot() can also accept more than two arguments.
© 2024 Rookie Tutorial. All rights reserved.
← Func Number SinFunc Number Cos β†’