Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

How to Find Factorial in Python using factorial() Function

To find factorial in Python you can use factorial() function from Standard math Library of Python Programming Language.

The product of an integer and all the integers below it is called factorial. For example, factorial of five ( 5! ) is equal to 120 by multiplying 5 * 4 * 3 * 2 * 1. ! (Sign of exclamation) is used to represent factorial in mathematics.

factorial() function exists in Standard math Library of Python Programming Language. The purpose of this function is to calculate factorial and return its value.

 

Python factorial() Function Syntax

The syntax of factorial function in python is:
math.factorial( x )

 

Python factorial() Function Parameters

x – Any valid Python number (positive). This parameter is required.
Note: if the x parameter is not a number or a negative number, factorial function will return an Value Error.

 

Python factorial() Function Compatibility

Python 2.x – Yes
Python 3.x – Yes

 

Python factorial() Function Return Value

The factorial function will return an integer value after calculating the factorial.

 

Python factorial() Function Example


Output of Python factorial() function:

120
5040
1307674368000
2432902008176640000

Note that if parameter x value of math.factorial( x ) function is negative then Python compiler raises ValueError exception.

 

LearnAndLearn.com © 2018 - All rights reserved