The math.comb()
function calculates the number of combinations of k items taken from a set of n items. This is also known as the binomial coefficient.
math.comb(n, k)
Where, parameter n
is the number of items in the set, and k
is the number of items taken from the set.
The function returns the number of combinations of k items that can be taken from a set of n items. It evaluates to n! / (k! * (n - k)!) when k <= n
. If k > n
, it evaluates to zero.
import math
print(math.comb(5, 10))
print(math.comb(5, 5))
print(math.comb(5, 2))
print(math.comb(10, 4))
print(math.comb(14, 8))