CKTIS / Python
math.factorial
Calcule la factorielle d’un entier positif ou nul.
Version : Python 3.14; repository image, production runtime not attested
Syntaxe
math.factorial(n, /)Calcule la factorielle d’un entier positif ou nul.
Pour n > 0, n! = n · (n−1)!, donc 5 · 4 · 3 · 2 · 1 donne 120. Pour n = 0, le produit vide vaut 1.
Un entier négatif lève ValueError et un float lève TypeError.
import math
assert math.factorial(5) == 5 * math.factorial(4) == 120
assert math.factorial(0) == math.factorial(1) == 1
Exemples
import math
print(math.factorial(5))
print(math.factorial(0))
Résultat
120 1
Un entier négatif lève ValueError et un float lève TypeError.