Partial functions in Python are especially useful when a function must be passed to another function or method. In these circumstances, we may want to set arguments in the passed function, such as the keyword argument
round_result on line #9. Using the built-in
partial function, we can set these arguments and create a new function with a smaller signature.
In this example,
score_function_with_rounding is a function with only a single argument,
data. Since the
score method does not care about any other arguments (such as
round_result), we can safely use the partial function instead of
A more in-depth overview of the
partial function can be found in the official Python docs.