Python factorial function


Python factorial(x) function returns the x factorial. x should be an integer and greater than 0. It's a method of math module.

x! = 1 * 2 * 3 * ... * (x-1) * x
0! = 1

>>> import math
>>> math.factorial(0)  #0!
1

>>> math.factorial(1)  #1!
1

>>> math.factorial(2)  #2!
2

>>> math.factorial(3)  #3!
6

>>> math.factorial(4)  #4!
24

>>> math.factorial(5)  #5!
120