compare approaches one problem · two ways
Compare Approaches
The same problem solved different ways in Python, run on the same input, with what really differs and when to use each.
lambda vs functools.partial
Make a ‘convert to EUR’ function from a general convert(amount, rate).
what differs
Both produce a callable. partial records the function and the bound arguments, so it's inspectable and can be sent to worker processes; a lambda is opaque but more flexible.
at a glance
| approach | use it when |
|---|---|
| A · lambda | When you also need to rearrange or transform arguments. |
| B · functools.partial | Pre-filling some arguments of an existing function; a partial shows what was bound (to_eur.keywords). |
Watch out: partial binds values when created; a lambda looks names up when called.
the outputs
Each approach runs on the same input.
concepts
functools.partialcurrying
learn it
Pure functions: same input, same output, no surprises
related comparisons