The factorial method of the math module
The factorial method of the math module returns the factorial of a number, i.e. the product of all natural numbers from 1 to the given number. Only a positive number can be passed in the method parameter, otherwise the method will return an error.
Syntax
import math
math.factorial(number)
Example
Let's find out the factorial of the number 5:
import math
print(math.factorial(5))
Result of code execution:
120
Example
Now let's apply the factorial method to the number -4:
import math
print(math.factorial(-4))
Result of code execution:
ValueError: factorial() not defined for negative values