Home >>Python math Module >Python math.factorial() Method

Python math.factorial() Method

Python math.factorial() Method

Python math.factorial() method in python is used to returns the factorial of the number and it only accepts the positive integer number , if the value is either a negative or float – it returns "ValueError" .

For example, the factorial of 4 would be 4 x 3 x 2 x 1 = 24

Syntax:
math.factorial(x)

Parameter Values

Parameter Description
x It is required a positive integer and returns the factorial number
Here is an example of Python math.factorial() Method:

import math  
print(math.factorial(3))
print(math.factorial(7))
print(math.factorial(11))

Output:
6
5040
39916800
Example 2:

import math
w = 12
x = 23
y = 5
z = 2
print("factorial of ", w, " is = ", math.factorial(w))
print("factorial of ", x, " is = ", math.factorial(x))
print("factorial of ", y, " is = ", math.factorial(y))
print("factorial of ", z, " is = ", math.factorial(z))

Output:
factorial of 12 is = 479001600
factorial of 23 is = 25852016738884976640000
factorial of 5 is = 120
factorial of 2 is = 2

No Sidebar ads