Python hypot() Function

Python 数字Python Numbers


Description

hypot()Returns the Euclidean norm, sqrt(x*x + y*y).


Syntax

The following is the syntax for the hypot() method:

import math

math.hypot(x, y)

Note:hypot() is not accessible directly; you need to import the math module, and then call this method via the math static object.


Parameters

  • x -- A numeric value.
  • y -- A numeric value.

Return Value

Returns the Euclidean norm sqrt(x*x + y*y).


Example

The following example shows the use of the 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)

The output of the above example is:

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

Python 数字Python Numbers

Other Extensions