Python hypot() 関数

Python 数字Python 数値


説明

hypot()ユークリッドノルム sqrt(x*x + y*y) を返します。


構文

以下は hypot() メソッドの構文です:

import math

math.hypot(x, y)

注意:hypot() は直接アクセスできません。math モジュールをインポートし、math 静的オブジェクトを介してこのメソッドを呼び出す必要があります。


引数

  • x -- 数値。
  • y -- 数値。

戻り値

ユークリッドノルム sqrt(x*x + y*y) を返します。


例

以下は hypot() メソッドを使用した例です:

#!/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)

上記の例を実行すると、出力は次のようになります:

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

Python 数字Python 数値

その他の拡張