Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python math.perm() Method

Python math.perm() Method

Python math Module Python math Module

Python math.perm(x, i) The method returns the total number of ways to choose k items from n items without repetition and with order.

Note: the k parameter is optional. If we do not set k, this method returns n! (for example, math.perm(7) returns 5040).

Python version: 3.8

Syntax

The syntax of the math.perm() method is as follows:

math.perm(n, k)

Parameter Description:

Note: if k is greater than n, 0 is returned.

Note: if n or k is negative, a ValueError occurs. If n or k is not an integer, a TypeError occurs.

Return Value

An integer int representing the total number of ways to choose k items from n items without repetition and with order.

Example

The following example computes the total number of ways to choose k items from n items:

Example

Import the math package

import

math

Initialize n

n

=

7

Initialize k

k

=

5

Output the total number of ways to choose k items from n items

print

(

math

.

perm

(

n

,

k

)

)

Output result:


2520

Python math Module Python math Module