math.factorial
Calculate the factorial, the product of all integers from 1 to n.
Python 3.13
math.factorial(n)Parameters
- nint
- A non-negative integer.
Return value
An int; raises ValueError for a negative n and TypeError for a non-integer.
Examples
Factorial of five
Python 3.13
import math
print(math.factorial(5))120
Factorial of zero
Python 3.13
import math
print(math.factorial(0))1
Details
The factorial of zero is 1. Floats are not accepted, not even 5.0.
