Python log()-Funktion

Python 数字Zahlen in Python


Beschreibung

log() gibt den natürlichen Logarithmus von x zurück.


Syntax

Die Syntax der log()-Methode lautet:

import math

math.log(x[, base])

Hinweis:log() ist nicht direkt zugänglich; Sie müssen das math-Modul importieren und die Methode über ein statisches Objekt aufrufen.


Parameters

  • x -- Numerischer Ausdruck.
  • base -- Optional, Basis, Standardwert ist e.

  • Rückgabewert

    Gibt den natürlichen Logarithmus von x zurück, wobei x>0.

    Beispiel

    Das Folgende zeigt ein Beispiel für die Verwendung der log()-Methode:

    Beispiel (Python 2.0+)

    #!/usr/bin/python # -*- coding: UTF-8 -*- import math # Importiere das math-Modul 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) # Setze die Basis print "math.log(10,2) : ", math.log(10,2)

    Die Ausgabe nach dem Ausführen des obigen Beispiels lautet:

    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 数字Zahlen in Python

    Andere Erweiterungen