Python Factorial: Using math.factorial()

The factorial function in Python is a function in the math module, and it can be called in the following way:

  1. Import the math module.
  2. Call the factorial function from the math module: math.factorial(n), with n being the number for which the factorial is required.

Here is a complete sample code:

import math

n = 5
result = math.factorial(n)
print(result)

The output is 120, which is the factorial of 5.

bannerAds