What is math.factorial() in Python?

Share

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.

Figure 1: Mathematical representation of the factorial() function and the corresponding representation in Python

The math module is required for this function.

Syntax

factorial(integer)

Parameter

This function requires a positive integer whose factorial is to be calculated.

Return value

factorial() returns the factorial of the positive integer sent as a parameter.

In the case of a non-integral value, an error is thrown.

Example

The following example shows how we can use the factorial() function in Python.

#Module required
import math
#example
print ("factorial(6) : ", math.factorial(6))
print ("factorial(4) : ", math.factorial(4))
print ("factorial(0) : ", math.factorial(0))