Python log() 関数

Python 数値


説明

log() は x の自然対数を返します。


構文

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

import math

math.log(x[, base])

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


パラメータ

  • x -- 数値式。
  • base -- 任意、底数、デフォルトは e。

  • 戻り値

    x の自然対数を返します(x > 0)。

    実例

    以下は log() メソッドの使用実例です:

    実例(Python 2.0+)

    #!/usr/bin/python # -*- coding: UTF-8 -*- import math # math モジュールをインポート print "math.log(100.12) : ", math.log(100.12) print "math.log(100.72) : ", math.log(100.72) print "math.log(119L) : ", math.log(119L) print "math.log(math.pi) : ", math.log(math.pi) # 底数を設定 print "math.log(10,2) : ", math.log(10,2)

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

    math.log(100.12) :  4.60636946656
    math.log(100.72) :  4.61234438974
    math.log(119L) :  4.77912349311
    math.log(math.pi) :  1.14472988585
    math.log(10,2) :  3.32192809489
    

    Python 数値

    その他の拡張