The factorial() function returns the factorial of a positive integer.
A factorial is a product of that positive integer and all the integers below it, until 1.
Figure 1 shows the mathematical representation of the factorial() function and the corresponding representation in Python.
The
mathmodule is required for this function.
factorial(integer)
This function requires a positive integer whose factorial is to be calculated.
factorial() returns the factorial of the positive integer sent as a parameter.
In the case of a
non-integral value, anerroris thrown.
The following example shows how we can use the factorial() function in Python.
#Module requiredimport math#exampleprint ("factorial(6) : ", math.factorial(6))print ("factorial(4) : ", math.factorial(4))print ("factorial(0) : ", math.factorial(0))