Home >>Python math Module >Python math.comb() Method

Python math.comb() Method

Python math.comb() Method

Python math.comb() Method in python is used to returns the number of ways picking k items from n items without repetition or order.

Syntax:
math.comb(n, k)

Parameter Values

Parameter Description
n It is required to choose items of positive integers
k It is required to choose positive integers of items
Here is an example of Python math.comb() Method:

import math
n = 7
k = 5
print (math.comb(n, k))

Output:
21
Example 2:

import math 
n = 10
k = 2
nCk = math.comb(n, k) 
print(nCk) 
n = 5
k = 3
nCk = math.comb(n, k) 
print(nCk)

Output:
45
10

No Sidebar ads