Python math.factorial() Method
Python math.factorial(x) The method returns the factorial of x.
The argument can only be a positive integer.
The factorial of a number is the product of all integers up to it; for example, the factorial of 6 is: 6 x 5 x 4 x 3 x 2 x 1 = 720.
Syntax
The syntax of the math.factorial() method is as follows:
math.factorial(x)
Parameter Description:
- x -- required, a positive integer. If the number is negative or not an integer, a ValueError is returned. If the value is not a number, a TypeError is returned.
Return Value
Returns a positive integer representing the factorial of the positive integer.
Example
The following example returns the factorial of positive integers:
Example
Import the math package
import
math
Output the factorial of positive integers
(
math
.
factorial
(
9
)
)
(
math
.
factorial
(
6
)
)
(
math
.
factorial
(
12
)
)
Output result:
362880
720
479001600
Python math Module