Easy Tutorial
❮ Pyhton Remove Ith Character From String Python Bank System ❯

Python math.perm() Method

Python math Module

The math.perm(x, i) method in Python 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 k is not set, this method will return n! (e.g., math.perm(7) will return 5040).

Python Version: 3.8

Syntax

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

math.perm(n, k)

Parameter Description:

Note: If k is greater than n, it returns 0.

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, representing the total number of ways to choose k items from n items without repetition and with order.

Example

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

Example

# Import 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

❮ Pyhton Remove Ith Character From String Python Bank System ❯