Python math.log() メソッド
Python math.log(x)メソッドは1つの引数を使用し、x の自然対数(底は e)を返します。
構文
math.log() メソッドの構文は次のとおりです:
math.log(x[, base])
パラメータの説明:
- x-- 必須、数値。x が数値でない場合、TypeError を返します。値が 0 または負の数の場合、ValueError を返します。
- base-- オプション、底、デフォルトは e です。
戻り値
浮動小数点数 float を返し、数値の自然対数を表します。
例
次の例は、数値の自然対数を返します:
例
# math パッケージをインポート
import math
# 数値の自然対数を出力
print(math.log(2.7183))
print(math.log(2))
print(math.log(1))
import math
# 数値の自然対数を出力
print(math.log(2.7183))
print(math.log(2))
print(math.log(1))
出力結果:
1.0000066849139877 0.6931471805599453 0.0その他の拡張
Python math モジュール