Méthode math.log2() en Python

Python math 模块Module math de Python

Python math.log2(x)La méthode renvoie le logarithme de base 2 de x.

Syntaxe

La syntaxe de la méthode math.log2() est la suivante :

math.log2(x)

Description des paramètres :

  • x-- Obligatoire, un nombre. Si x n'est pas un nombre, renvoie TypeError. Si la valeur est 0 ou négative, renvoie ValueError.

Valeur de retour

Renvoie un nombre à virgule flottante (float), représentant le logarithme de base 2 d'un nombre.

Exemple

L'exemple suivant renvoie le logarithme de base 2 d'un nombre :

Exemple

# Importer le package math
import math

# Afficher le logarithme de base 2 d'un nombre
print(math.log2(2.7183))
print(math.log2(2))
print(math.log2(1))

Sortie :

1.4427046851812222
1.0
0.0

Python math 模块Module math de Python

Autres extensions