Skip to main content

← All terms Β· Functions

functools.partial

Pre-bind some arguments of a function β€” produces a new callable with fewer parameters. Cleaner than a wrapping lambda for currying-style use.

from functools import partial
double = partial(int, base=2)  # int("110", base=2) β†’ 6

Learn this interactively:

Open lesson sr-108 β†’

Related β€” Functions

FunctionNamed reusable block of code. Defined with `def`. First-class β€” you can pass fun…Default argumentParameter with a fallback value: `def f(x=10)`. Beware mutable defaults β€” `def f…*args, **kwargsCapture variable positional and keyword arguments. Lets a function accept any si…LambdaAn anonymous one-line function: `lambda x: x*2`. Use for short callbacks; prefer…DecoratorA higher-order function that wraps another to add behavior β€” logging, caching, a…ClosureAn inner function that captures variables from its enclosing scope. The captured…