» » » Python Factorial

# Calculating Factorials in Python – The Easy Way

This short article will show you the quickest and easiest way to calculate a factorial in Python using the factorial() function.

## What is a Factorial, and How is it Calculated?

factorial is a mathematical formula in which a given positive integer is multiplied by all of the positive integers less than itself – the resulting number being the factorial of the original number.

It is denoted with ! (exclamation mark) – so the factorial of 4 is written as

```4!
```

And is calculated out like so:

```4 * 3 * 2 * 1 = 24
```

You can find out more about factorials themselves on Wikipedia.

## The Python Factorial Function

You could write a Python function that does the above calculation yourself – but you don’t have to!

Python already has a built-in factorial function ready to do the job for you. It’s in the math library – just import it and use it:

```import math
factorial = math.factorial(4)
print(factorial)```

Easy!