As per python docs “The
functools module is for higher-order functions: functions that act on or return other functions.“
functoolsis certainly partial, which provides ability to set a subset of arguments expected by a function. This partially set function can now be passed to the next consumer to provide rest of the arguments and finally invoke the function. Objects returned by
partial are instances of
Partial, and can further be chained if we desire to provide few more arguments but not want to invoke the function yet.
Put simply, partial provides a way to achieve a class like behavior from a function, where the instance is created with certain arguments. These arguments define the character of the function in later operations.
Simple example of this kind of implementation is a generic power function where the order changes based upon initial argument
A more practical example of partial could be a method to execute remote commands.