A combination selects items when their order does not matter. It supports probability calculations and contrasts with a permutation, where arrangement order matters. section 2.2.3 section 2.0
Choose the formula according to whether selected items can be reused:
- Without replacement: C(n, r) = n! / [r!(n − r)!]. For n = 5 and r = 3, the result is 10. section 2.2.3
- With replacement: C(n + r − 1, r) = (n + r − 1)! / [r!(n − 1)!]. For n = 5 and r = 3, the result is 35. section 2.2.3
- Python provides math.comb(n, r) for these integer calculations; factorial expressions expose the underlying formulas. section 2.2.3
Starting lineup and Pascal’s triangle
A basketball starting lineup is a combination because the introduction order does not change the selected group. Pascal’s triangle also gives C(5, 3) = 10 at the sixth row and fourth position. section 2.2.3
>>> n = 5
>>> r = 3
>>> combinations = (math.factorial(n) / \
>>> (math.factorial(r) * math.factorial(n - r)))
>>> print(f'Number of combinations without replacement: '
>>> f'{combinations}')
Number of combinations without replacement: 10.0
>>> combinations = math.comb(n, r)
>>> print(f'Number of combinations without replacement: '
>>> f'{combinations}')
Number of combinations without replacement: 10
Inspect executable Python for factorial and math.comb implementations of combinations without replacement. section 2.2.3


