无聊而有用的争论-Python应该用驼峰命名还是下划线命名

stackoverflow链接:

1.https://stackoverflow.com/questions/159720/what-is-the-naming-convention-in-python-for-variable-and-function-names

结论:PEP8 规定是:为了更好的可读性,应该用下划线来命名变量

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

Use the function naming rules: lowercase with words separated by underscores as necessary to improve readability.

Google Python Style Guide 的例子:

module_name, package_name, ClassName, method_name, ExceptionName, function_name, GLOBAL_CONSTANT_NAME, global_var_name, instance_var_name, function_parameter_name, local_var_name

2.另一个讨论:

https://stackoverflow.com/questions/8908760/should-i-use-camel-case-or-underscores-in-python

结论:

应该用:

def my_function():
而不是:
def myFunction():
posted @ 2017-11-25 15:54  Eason的博客  阅读(1976)  评论(0编辑  收藏  举报