Python math.factorial() Method

❮ Math Methods


Example

Find the factorial of a number:

#Import math Library
import math

#Return factorial of a number
print(math.factorial(9))
print(math.factorial(6))
print(math.factorial(12))
Try it Yourself »

Definition and Usage

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

Note: This method only accepts positive integers.

The factorial of a number is the sum of the multiplication, of all the whole numbers, from our specified number down to 1. For example, the factorial of 6 would be 6 x 5 x 4 x 3 x 2 x 1 = 720


Syntax

math.factorial(x)

Parameter Values

Parameter Description
x Required. A positive integer. If the number is negative, or not an integer, it returns a ValueError. If the value is not a number, it returns a TypeError

Technical Details

Return Value: A positive int value
Python Version: 2.6

❮ Math Methods

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.