Open In App

Python math function | hypot()

Last Updated : 29 Dec, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

hypot() function is an inbuilt math function in Python that return the Euclidean norm, \sqrt{(x*x + y*y)} . Syntax :

hypot(x, y) 

Parameters :

x and y are numerical values 

Returns :

Returns a float value having Euclidean norm, sqrt(x*x + y*y). 

Error :

When more than two arguments are 
passed, it returns a TypeError.

Note : One has to import math module before using hypot() function.   Below is the demonstration of hypot() function : Code #1 : 

Python3

# Python3 program for hypot() function
 
# Import the math module
import math
 
# Use of hypot function
print("hypot(3, 4) : ", math.hypot(3, 4))
 
# Neglects the negative sign
print("hypot(-3, 4) : ", math.hypot(-3, 4))
 
print("hypot(6, 6) : ", math.hypot(6, 6))

                    

Output :

hypot(3, 4) :  5.0
hypot(-3, 4) :  5.0
hypot(6, 6) :  8.48528137423857

  Code #2 : 

Python3

# Python3 program for error in hypot() function
 
# import the math module
import math
 
# Use of hypot() function
print("hypot(3, 4, 6) : ",  math.hypot(3, 4, 6))

                    

Output : 

Traceback (most recent call last):
  File "/home/d8c8612ee97dd2c763e2836de644fac1.py", line 7, in 
    print("hypot(3, 4, 6) : ",  math.hypot(3, 4, 6))
TypeError: hypot expected 2 arguments, got 3

  Practical Application : Given perpendicular and base of a right angle triangle find the hypotenuse. Using Pythagorean theorem which states that the square of the hypotenuse (the side opposite the right angle) is equal to the sum of the squares of the other two sides. Hence,

 Hypotenuse = sqrt(p^2 + b^2) 

Code #3 : 

Python3

# Python3 program for finding Hypotenuse
# in hypot() function
 
# import the math module
from math import hypot
 
# Perpendicular and base
p = 3
b = 4
 
# Calculates the hypotenuse
print("Hypotenuse is:", hypot(p, b))

                    

Output :

Hypotenuse is: 5.0


Similar Reads

numpy.hypot() in Python
This mathematical function helps user to calculate hypotenuse for the right angled triangle, given its side and perpendicular. Result is equivalent to Equivalent to sqrt(x1**2 + x2**2), element-wise. Syntax : numpy.exp2(arr1, arr2[, out]) = ufunc 'hypot') : Parameters : arr1, arr2 : [array_like] Legs(side and perpendicular) of triangle out : [ndarr
2 min read
Python math.sqrt() function | Find Square Root in Python
sqrt() function returns square root of any number. It is an inbuilt function in Python programming language. In this article, we will learn more about the Python Program to Find the Square Root. sqrt() Function We can calculate square root in Python using the sqrt() function from the math module. In this example, we are calculating the square root
3 min read
Python math function | modf()
modf() function is an inbuilt function in Python that returns the fractional and integer parts of the number in a two-item tuple. Both parts have the same sign as the number. The integer part is returned as a float. Syntax : modf(number) Time Complexity: O(1) Auxiliary Space: O(1) Parameter : There is only one mandatory parameter which is the numbe
3 min read
Python | math.fabs() function
In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math.fabs() function returns the absolute value of the number. Syntax: math.fabs(x) Parameter: x: This is a numeric expression. Returns: the absolute value of the number. Time Complexity: O(1) Auxiliary Space: O(1) Code #1: C/C++
1 min read
Python | math.floor() function
In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math.floor() function returns the largest integer not greater than x. If number is already integer, same number is returned. Syntax: math.floor(x) Parameter: x: This is a numeric expression. Returns: largest integer not greater th
1 min read
Python math function | copysign()
math.copysign() is a function exists in Standard math Library of Python. This function returns a float value consisting of magnitude from parameter x and the sign (+ve or -ve) from parameter y. Syntax : math.copysign(x, y) Parameters : x : Integer value to be converted y : Integer whose sign is required Returns : float value consisting of magnitude
1 min read
Python | math.ceil() function
In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math.ceil() function returns the smallest integral value greater than the number. If number is already integer, same number is returned. Syntax: math.ceil(x) Parameter: x: This is a numeric expression. Returns: Smallest integer no
1 min read
Python | math.factorial() function
In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math.factorial() function returns the factorial of desired number. Syntax: math.factorial(x) Parameter: x: This is a numeric expression. Returns: factorial of desired number. Time Complexity: O(n) where n is the input number. Auxi
2 min read
Python | math.copysign() function
In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math.copysign(a, b) function return a float with the magnitude (absolute value) of a but the sign of b. Syntax: math.copysign(a, b) Parameter: a, b: numeric values. Returns: Return absolute value of a but the sign of b. Code #1: #
1 min read
Python | math.gcd() function
In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math.gcd() function compute the greatest common divisor of 2 numbers mentioned in its arguments. Syntax: math.gcd(x, y) Parameter: x : Non-negative integer whose gcd has to be computed. y : Non-negative integer whose gcd has to be
2 min read
Practice Tags :