Python math.pow() メソッド
Python math.pow(x, y)メソッドは x の y 乗(累乗)を返します。
x が負で y が整数でない場合、ValueError を返します。 このメソッドは両方の引数を浮動小数点数に変換します。 math.pow(1.0, x) または math.pow(x, 0.0) は常に 1.0 を返します。構文
math.pow() メソッドの構文は次のとおりです:
math.pow(x, y)
パラメータの説明:
- x-- 必須。基数を表す数値。
- y-- 必須。指数を表す数値。
戻り値
x の y 乗を表す浮動小数点数を返します。
例
次の例は 9 の 3 乗を返します:
例
# math パッケージをインポート
import math
# 9 の 3 乗を出力
print(math.pow(9, 3))
import math
# 9 の 3 乗を出力
print(math.pow(9, 3))
出力結果:
729.0その他の拡張
Python math モジュール