logo

Python Number Hypot() Method


Show

Description

The hypot() method in python’s math module returns the Euclidean norm, sqrt(x*x + y*y). The hypot() method of math module in Python is defined in the math library where the hypot() method is utilized to find out the value of the euclidean norm. For two different numbers x and y, the euclidean norm refers to the length of the vector i.e. from origin (0,0) to the coordinate (x,y).

Syntax

Here is the syntax for hypot() method:

hypot(x, y)

Note - One cannot access this function directly, so it is required to import the math module in Python, and then we are supposed to call this function making use of the math static object.

Parameters

  • x - This should be a numeric value.
  • y - This should be a numeric value.

Return Value

This method in the Python math module returns the Euclidean norm, sqrt(x*x + y*y).

Example

The example below shows the usage of hypot() method.

#!/usr/bin/python
import math

print "hypot(3, 2) : ",  math.hypot(3, 2)
print "hypot(-3, 3) : ",  math.hypot(-3, 3)
print "hypot(0, 2) : ",  math.hypot(0, 2)

When the above program is run, it produces following result:

hypot(3, 2) :  3.60555127546
hypot(-3, 3) :  4.24264068712
hypot(0, 2) :  2.0

Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.