0
Can anyone explain **kwargs to me?
2 Answers
+ 2
Keyword arguments stores the keys with values like dictionary
0
Taking the example from the course:
def my_func(x, y=7, *args, **kwargs):
print(kwargs)
my_func(2, 3, 4, 5, 6, a=7, b=8)
If you consider the arguments passed to my_func, 2 will be x, 3 will be a non-default value for y, 4, 5 and 6 will be the tuple args and a=7 and b=8 will become the dict kwargs.
So args = (4, 5, 6) and kwargs = {'a': 7, 'b': 8}