Python Tutorial Python Advanced Python References Python Libraries

Python math - perm() Function



The Python math.perm() function returns the number of ways to choose k items from n items without repetition and with order. It is also known as permutations and mathematically can be expressed as:

permutations

Where k ≤ n. If k > n, the function returns zero.

Syntax

#New in version 3.8
math.perm(n, k)   

Parameters

n Required. Specify the number of item to choose from.
k Required. Specify the number of item to choose.

Return Value

Returns the number of ways to choose k items from n items without repetition and with order.

Exceptions

  • Throws TypeError if either of the arguments are not integers.
  • Throws ValueError if either of the arguments are negative.

Example:

The example below shows the usage of perm() function.

import math

#choosing 2 items from 3 items
#without repetition and with order
print(math.perm(3, 2))

#choosing 3 items from 10 items
#without repetition and with order
print(math.perm(10, 3))

The output of the above code will be:

6
720

❮ Python Math Module

5