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

标签 naming-conventions pep8

来自函数和方法参数的 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/

相关文章:

design-patterns - 在命令模式中,将其他命令组合在一起的命令称为什么?

python - 打破长if语句的推荐方法是什么? (二元运算符后的 W504 换行符)

c - 多用途结构方法的命名约定

python - 导入常用模块缩写

Go 惯用的类型转换函数命名

python - "E721: do not compare types, use isinstance()"错误

python - 顶级变量赋值或方法调用之间有多少空行?

java - 使用 Java 命名约定将 Python 对象(使用 Python 约定)编码为 JSON

python - 为什么一些 python 变量是大写的而其他的是小写的?

python - __init__ 可以用作正常的初始化方法,而不是构造函数吗?