Python math.factorial()
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
nis negative or non-integer,math.factorial(n)raises aValueError. Ifnis not a number, it raises aTypeError.
Example
In the example we are using math.factorial() to return the factorial of 6:
import mathprint(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:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
- With Certificate
- Beginner Friendly.24 hours