Differences between functools.partial and a similar lambda?

  1. A lambda function has the same type as a standard function, so it will behave like an instance method.

  2. The partial object in your example can be called like this:

    g1(x, y, z)

    leading to this call (not valid Python syntax, but you get the idea):

    f(*secondary_args, x, y, z, **secondary_kwargs)

    The lambda only accepts a single argument and uses a different argument order. (Of course both of these differences can be overcome – I’m just answering what the differences between the two versions you gave are.)

  3. Execution of the partial object is slightly faster than execution of the equivalent lambda.

Leave a Comment