math.factorial()

yuekaim1029825402's avatar
Published Sep 29, 2024
Contribute to Docs

The math.factorial() method returns the factorial of a positive number.

Syntax

math.factorial(n)
  • n: A positive number whose factorial is calculated.

Note: If n is negative or non-integer, math.factorial(n) raises a ValueError. If n is not a number, it raises a TypeError.

Example

In the example we are using math.factorial() to return the factorial of 6:

import math
print(math.factorial(6))

The above code gives the following output:

720

Codebyte Example

Run the following example that uses the math.factorial() function to understand its working:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn Python on Codecademy