Méthode math.log() de Python
Python math.log(x)La méthode prend un argument et renvoie le logarithme népérien de x (base e).
Syntaxe
La syntaxe de la méthode math.log() est la suivante :
math.log(x[, base])
Description des paramètres :
- x-- Obligatoire. Un nombre. Si x n'est pas un nombre, une TypeError est renvoyée. Si la valeur est 0 ou négative, une ValueError est renvoyée.
- base-- Facultatif. La base, la valeur par défaut est e.
Valeur de retour
Renvoie un float, représentant le logarithme népérien d'un nombre.
Exemple
L'exemple suivant renvoie le logarithme népérien d'un nombre :
Exemple
# Importer le package math
import math
# Affiche le logarithme népérien d'un nombre
print(math.log(2.7183))
print(math.log(2))
print(math.log(1))
import math
# Affiche le logarithme népérien d'un nombre
print(math.log(2.7183))
print(math.log(2))
print(math.log(1))
Résultat de sortie :
1.0000066849139877 0.6931471805599453 0.0Autres extensions
Module math de Python