Méthode Python math.pow()

Python math 模块Module math de Python

Python math.pow(x, y)La méthode renvoie x élevé à la puissance y.

Si x est négatif et y n'est pas un entier, une ValueError est renvoyée. La méthode convertit les deux arguments en nombres à virgule flottante. math.pow(1.0, x) ou math.pow(x, 0.0) renvoie toujours 1.0.

Syntaxe

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

math.pow(x, y)

Description du paramètre :

  • x-- Obligatoire, un nombre représentant la base.
  • y-- Obligatoire, un nombre représentant l'exposant.

Valeur de retour

Renvoie un nombre à virgule flottante représentant x élevé à la puissance y.

Exemple

L'exemple suivant renvoie 9 à la puissance 3 :

Exemple

# Importer le package math
import math

# Sortie : 9 à la puissance 3
print(math.pow(9, 3))

Résultat de sortie :

729.0

Python math 模块Module math de Python

Autres extensions