Python 约定 **kwargs、**kwds、**kw 是什么?

发布于 2024-11-16 17:11:13 字数 44 浏览 4 评论 0原文

是否有关键字参数的Python命名约定?

Is there a python naming convention for key word arguments?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

筑梦 2024-11-23 17:11:13

不,但通常它被命名为 **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.

脱离于你 2024-11-23 17:11:13

最流行的约定是 **kwargs,如文档和 PEP 中所示。

The most popular convention is **kwargs, as seen in documentation and PEPs.

恬淡成诗 2024-11-23 17:11:13

关键是一致性。在您的个人代码和您正在处理的项目中。如果我正在阅读您的代码并看到您在所有函数中使用 **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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文