Easy Tutorial
❮ Python String Rfind Ref Set Intersection ❯

Python math.comb() Method

Python math Module

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

The parameters must be positive integers.

Python version: 3.8

Syntax

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

math.comb(n, k)

Parameter Description:

Return Value

Returns an integer representing the total number of combinations.

Example

The following example returns the total number of ways to choose 7 items from 5 items:

Example

# Import math package
import math

# Initialize the number of items to choose from
n = 7

# Initialize the number of possibilities to choose
k = 5

# Print the total number of possible combinations
print (math.comb(n, k))

Output result:

21

Python math Module

❮ Python String Rfind Ref Set Intersection ❯