This question already has an answer here:
So I have difficulty with the concept of *args
and **kwargs
.
So far I have learned that:
-
*args
= list of arguments - as positional arguments -
**kwargs
= dictionary - whose keys become separate keyword arguments and the values become values of these arguments.
I don't understand what programming task this would be helpful for.
Maybe:
I think to enter lists and dictionaries as arguments of a function AND at the same time as a wildcard, so I can pass ANY argument?
Is there a simple example to explain how *args
and **kwargs
are used?
Also the tutorial I found used just the "*" and a variable name.
Are *args
and **kwargs
just placeholders or do you use exactly *args
and **kwargs
in the code?
</div>
转载于:https://stackoverflow.com/questions/3394835/args-and-kwargs