logo

... args kwargs: unpacking



Notes

The example below contains the call that is able to unpack both the *args as well as the **kwargs.

def function(a, b, *args, keyword=True, **kwargs):
    print(a, b)
    print(args)
    print(keyword)
    print(kwargs)

d = {'param_a': 43, 'param_b': 44}
function(1, 2, *[5, 3, 4], param=42, **d)

Feel free to play with the code until you understand the print statements. Pay attention to the symmetry between * and ** arguments.

Feedback? See an issue? Something unclear? Feel free to mention it here.



If you want to be kept up to date, consider signing up for the newsletter.