python has two types of variable length arguments:
*args
(Non Keyword Arguments)
**kwargs
(Keyword Arguments)
When you define a function with *args
, you effectively take arguments and collect them into a list. So;
def foo(*a):
# a here is a tuple: (2,3,4,5)
print(a)
foo(2,3,4,5)
>>>
(2,3,4,5)
When you define a function with **kwargs
, you effectively take named arguments and collect them into a dict. So;
def zoo(**b):
# b here is a dict: {'test': 2, 'abc': 'def'}
print(b)
zoo(test=2, abc='def')
>>>
{'test': 2, 'abc': 'def'}
When you want to pass variable arguments from a list or a dict, you can use similarly:
def xxx(a=2, b=4):
print(a+b)
kw = {'a': 5, 'b': 7}
xxx(**kw)
>>>
12
see: https://www.programiz.com/python-programming/args-and-kwargs#:~:text=Python%20has%20*args%20which%20allow,to%20pass%20variable%20length%20arguments.