The math.factorial()
function is used to calculate the factorial of a given number. The factorial of a number n is written as n! and is equal to the product of all positive integers less than or equal to n
. For example the factorial of 5 is 120, because 5 x 4 x 3 x 2 x 1 = 120
.
math.factorial(n)
copy
Where, parameter n
is an non-negative integer whose factorial is to be calculated.
If n
is not a non integer, a TypeError
is raised. Whereas, if n
is a negative number, a ValueErro
r is raised.