So I have difficulty with the concept of *args
and **kwargs
. (所以我很难理解*args
和**kwargs
的概念。)
So far I have learned that: (到目前为止,我已经了解到:)
-
*args
= list of arguments - as positional arguments (*args
=参数列表-作为位置参数) -
**kwargs
= dictionary - whose keys become separate keyword arguments and the values become values of these arguments. (**kwargs
=字典-其键成为单独的关键字参数,而值则成为这些参数的值。)
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? (我认为要输入列表和字典作为函数的参数,并与通配符同时输入,因此我可以传递ANY参数吗?)
Is there a simple example to explain how *args
and **kwargs
are used? (有一个简单的示例来说明如何使用*args
和**kwargs
吗?)
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? (*args
和**kwargs
只是占位符还是在代码中使用了*args
和**kwargs
?)