Back to 30 Seconds Of Code

Binomial coefficient

content/snippets/python/s/binomial-coefficient.md

14.0.0327 B
Original Source

The binomial coefficient is the number of ways to choose k items from n items without repetition and without order. In Python, you can calculate the binomial coefficient using the math.comb() function.s

py
from math import comb

def binomial_coefficient(n, k):
  return comb(n, k)

binomial_coefficient(8, 2) # 28