Applying Keyword Arguments
Learn how partial functions apply keyword arguments. Also, look at scenarios where you can do without partial application.
We'll cover the following...
We'll cover the following...
How to apply keyword arguments
A partial function can apply keyword arguments too. Here is a simple example:
Python 3.8
def make_print(sep):def f(*args):return print(*args, sep=sep)return fprint_csv = make_print(', ')print_colon = make_print(':')print_csv(1, 2, 3) # 1, 2, 3print_colon(1, 2, 3) # 1:2:3
The make_print function returns a partial application of the standard print function with the sep keyword argument set to the supplied value. sep is a string that gets inserted between the arguments (this is standard ...