Python math.factorial() Method
Python math.factorial(x)The method returns the factorial of x.
The parameter can only be a positive integer.
The factorial of a number is the product of all integers, 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, positive integer. If the number is negative or not an integer, it returns ValueError. If the value is not a number, it returns TypeError.
Return Value
Returns a positive integer representing the factorial of the positive integer.
Example
The following example returns the factorial of a positive integer:
Example
# Import the math package
import math
# Output the factorial of a positive integer
print(math.factorial(9))
print(math.factorial(6))
print(math.factorial(12))
import math
# Output the factorial of a positive integer
print(math.factorial(9))
print(math.factorial(6))
print(math.factorial(12))
Output result:
362880 720 479001600Other Extensions
Python math Module