How does functools partial do what it does?

Roughly, partial does something like this (apart from keyword args support etc): So, by calling partial(sum2, 4) you create a new function (a callable, to be precise) that behaves like sum2, but has one positional argument less. That missing argument is always substituted by 4, so that partial(sum2, 4)(2) == sum2(4, 2) As for why it’s needed, there’s a variety of cases. … Read more