# Calling it's factorial recursively
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
# Fastest way in Python 2.6+
import math
math.factorial(n)

Factorial function written in Python. To calculate the factorial of a non-negative integer x, just multiply all the integers from 1 through x.

For example:

factorial(4) would equal 4 * 3 * 2 * 1, which is 24.

factorial(1) would equal 1.

factorial(3) would equal 3 * 2 * 1, which is 6.

For example:

factorial(4) would equal 4 * 3 * 2 * 1, which is 24.

factorial(1) would equal 1.

factorial(3) would equal 3 * 2 * 1, which is 6.

## Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.