Python hypot() Function | Rookie Tutorial
Rookie Tutorial -- Learning not just technology, but dreams!
Python Basic Tutorials
- Python Basic Tutorial
- Python Introduction
- Python Environment Setup
- Python Chinese Encoding
- Python VS Code
- Python Basic Syntax
- Python Variable Types
- Python Operators
- Python Conditional Statement
- Python Loop Statements
- Python While Loop Statement
- Python for Loop Statement
- Python Nested Loops
- Python break Statement
- Python continue Statement
- Python pass Statement
- Python Number (Numbers)
- Python Strings
- Python Lists (List)
- Python Tuples
- Python Dictionary
- Python Date and Time
- Python Functions
- Python Modules
- Python File I/O
- Python File Methods
- Python Exception Handling
- Python OS File/Directory Methods
- Python Built-in Functions
Python Advanced Tutorials
- Python Object-Oriented
- Python Regular Expressions
- Python CGI Programming
- Python MySQL
- Python Network Programming
- Python SMTP Sending Email
- Python Multithreading
- Python XML Parsing
- Python GUI Programming (Tkinter)
- Python 2.x vs 3.x Version Differences
- Python IDE
- Python JSON
- Python AI Drawing
- Python 100 Examples
- Python Quiz
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
mathmodule 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.
YouTip