使用* args和** kwargs [重复]

你。 提交于 2020-04-05 20:53:18

问题:

This question already has answers here : 这个问题已经在这里有了答案
Closed 6 years ago . 6年前关闭。

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


解决方案:

参考一: https://stackoom.com/question/EF9P/使用-args和-kwargs-重复
参考二: https://oldbug.net/q/EF9P/Use-of-args-and-kwargs-duplicate
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!