Python sqrt() 関数

Python 数値


説明

sqrt()このメソッドは数値 x の平方根を返します。


構文

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

import math

math.sqrt( x )

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


パラメータ

  • x -- 数値式。

戻り値

数値 x の平方根を返します。

例

以下に sqrt() メソッドを使用した例を示します:

#!/usr/bin/python
import math   # This will import math module

print "math.sqrt(100) : ", math.sqrt(100)
print "math.sqrt(7) : ", math.sqrt(7)
print "math.sqrt(math.pi) : ", math.sqrt(math.pi)

上記の例を実行した後の出力結果は次のとおりです:

math.sqrt(100) :  10.0
math.sqrt(7) :  2.64575131106
math.sqrt(math.pi) :  1.77245385091

Python 数値

その他の拡張