Python hypot

The Python hypot function returns the square root of the sum of squares of the specified arguments. In this section, we discuss how to use hypot function in Python with an example.

The syntax of the math hypot Function in Python Programming Language is

math.hypot(Value1, Value2, ...ValueN);

Value1…ValueN: Valid numerical expression.

  • If the value argument is a positive integer and Negative integer, hypot function returns the Output.
  • If it is not a number, hypot function return TypeError.

Python hypot Function Example

The Python hypot function finds the square root of the sum of squares of a given number. In this hypot example, We are going to find the sum of squares of the square root of different data types and display the output.

# Python HYPOT Function

import math

Tup = (1, 2, 3, -4 , 5)
Lis = [-1, 2, -3.5, -4 , 7.5]

print('HYPOT value of Positive Number = %.2f' %math.hypot(2, 3))
print('HYPOT value of Negative Number = %.2f' %math.hypot(2, -4))

print('HYPOT value of Tuple Item = %.2f' %math.hypot(Tup[3], Tup[2]))
print('HYPOT value of List Item = %.2f' %math.hypot(Lis[2], Lis[4]))

print('HYPOT value of Multiple Number = %.2f' %math.hypot(2 + 7 - 4, 9 - 5))

print('HYPOT value of String Number = %.2f', math.hypot('Hello', 'Python'))
Python HYPOT Function

First, we used the hypot Function directly on both the Positive integer and negative integer. The following Python statements find the square root of the sum of squares of the corresponding values.

print('HYPOT value of Positive Number = %.2f' %math.hypot(2, 3))
print('HYPOT value of Negative Number = %.2f' %math.hypot(2, -4))

Next, We used the hypot Function on Tuple and List items. As you see, hypot function is working perfectly on them.

print('HYPOT value of Tuple Item = %.2f' %math.hypot(Tup[3], Tup[2]))
print('HYPOT value of List Item = %.2f' %math.hypot(Lis[2], Lis[4]))

Next, we used the hypot Math function on multiple values.

print('HYPOT value of Multiple Number = %.2f' %math.hypot(2 + 7 - 4, 9 - 5))

Within the last statement, we tried the hypot Function on the String value, and it returns TypeError.

print('HYPOT value of String Number = %.2f', math.hypot('Hello', 'Python'))