gpt4 book ai didi

naming-conventions - PEP 8 : Function and method arguments naming convention

转载 作者:行者123 更新时间:2023-12-04 07:54:29 28 4
gpt4 key购买 nike

来自函数和方法参数的 PEP 8 部分:

Always use self for the first argument to instance methods.

Always use cls for the first argument to class methods.

If a function argument's name clashes with a reserved keyword, it is generally better to append a >single trailing underscore rather than use an abbreviation or spelling corruption. Thus class_ is >better than clss. (Perhaps better is to avoid such clashes by using a synonym.)



没有说明首选命名风格,我想应该是“lower_case_with_underscores”或“mixedCase”,但我不确定。什么是首选?

最佳答案

来自 PEP 8 部分,紧接在您引用的部分之上。

Function Names

Function names should be lowercase, with words separated by underscores as necessary to improve readability.

mixedCase is allowed only in contexts where that's already the prevailing style(e.g. threading.py), to retain backwards compatibility.


链接: https://www.python.org/dev/peps/pep-0008/#function-names

关于naming-conventions - PEP 8 : Function and method arguments naming convention,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16785920/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com