On this page
math.comb
Prev: math.ceil | Up: math | Next: math.copysign
Rel: math.acos, math.acosh, math.asin, math.asinh
Ref: docs.python.org — math.comb
Tags: #public #python3 #stdlib #math
Import
import math
from math import comb
Signature & Overview
math.comb(n, k, /)
Number of ways to choose k items from n items without repetition and without order.
Usage
import math
assert math.comb(5, 2) == 10
assert math.comb(5, 6) == 0
Gotchas
- Exact arbitrary-precision
int: Much faster and overflow-free compared tofactorial(n) // (factorial(k) * factorial(n - k)).
REPL Inspect
from math import comb
help(comb)
Linked from
Related notes
- tuts/python3/stdlib_module/math/ceil Linked here; links to this page; shared tags: #math, #stdlib
- tuts/python3/stdlib_module/math/copysign Linked here; links to this page; shared tags: #math, #stdlib
- tuts/python3/stdlib_module/math Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/math/acos Linked here; shared tags: #math, #stdlib
- tuts/python3/stdlib_module/math/acosh Linked here; shared tags: #math, #stdlib
- tuts/python3/stdlib_module/math/asin Linked here; shared tags: #math, #stdlib
- tuts/python3/stdlib_module/math/asinh Linked here; shared tags: #math, #stdlib
- tuts/c/stdlib/math shared tags: #math, #stdlib
- tuts/c/stdlib/math/fabs shared tags: #math, #stdlib
- tuts/c/stdlib/math/floor shared tags: #math, #stdlib