Python 约定 **kwargs、**kwds、**kw 是什么?
是否有关键字参数的Python命名约定?
Is there a python naming convention for key word arguments?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
是否有关键字参数的Python命名约定?
Is there a python naming convention for key word arguments?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
不,但通常它被命名为
**kwargs
,但您可以将其命名为任何您想要的名称。唯一的问题是它应该出现在任何位置 args 和命名 args 之后的最后。Nope, but normally it is named as
**kwargs
, but you can name it anything you want. Only thing is it should come at the last following any position args and named args.最流行的约定是
**kwargs
,如文档和 PEP 中所示。The most popular convention is
**kwargs
, as seen in documentation and PEPs.关键是一致性。在您的个人代码和您正在处理的项目中。如果我正在阅读您的代码并看到您在所有函数中使用
**kwarguments
,我可以校准自己以更好地阅读它。如果您在一个地方使用**k
而在另一个地方使用**kargs
,那就是另一回事了。至于Python代码中的约定,我的经验与Senthil的相同 -
**kwargs
。The key is consistency. In your personal code and in the project on which you're working. If I'm reading your code and see you using
**kwarguments
in all functions, I can calibrate myself to read it fine. If you use**k
in one place and**kargs
in another, that's a different story.As for conventions in Python code generally, my experience is the same as Senthil's -
**kwargs
.