CKTIS / Python
math.comb
Zählt Auswahlen von k aus n Positionen ohne Zurücklegen und ohne Beachtung der Reihenfolge.
Version: Python 3.14; repository image, production runtime not attested
Syntax
math.comb(n, k, /)Zählt Auswahlen von k aus n Positionen ohne Zurücklegen und ohne Beachtung der Reihenfolge.
Fünf mal vier ergibt 20 geordnete Paare, geteilt durch zwei bleiben 10 Auswahlen. Für k > n folgt 0.
Negative Zahlen lösen ValueError aus, ein float löst TypeError aus.
import math
assert math.comb(5, 2) == 5 * 4 // 2
assert math.comb(5, 0) == 1 and math.comb(2, 5) == 0
Beispiele
import math
print(math.comb(5, 2))
print(math.comb(2, 5))
Ergebnis
10 0
Negative Zahlen lösen ValueError aus, ein float löst TypeError aus.