Python编码规范

PEP8编码规范

https://legacy.python.org/dev/peps/pep-0008/#id15

编码规范很重要!!!

A Foolish Consistency is the Hobgoblin of Little Minds

One of Guido's key insights is that code is read much more often than it is written. The guidelines provided here are intended to improve the readability of code and make it consistent across the wide spectrum of Python code. As PEP 20 says, "Readability counts".

A style guide is about consistency. Consistency with this style guide is important. Consistency within a project is more important. Consistency within one module or function is the most important.

However, know when to be inconsistent -- sometimes style guide recommendations just aren't applicable. When in doubt, use your best judgment. Look at other examples and decide what looks best. And don't hesitate to ask!

In particular: do not break backwards compatibility just to comply with this PEP!

Some other good reasons to ignore a particular guideline:

  1. When applying the guideline would make the code less readable, even for someone who is used to reading code that follows this PEP.
  2. To be consistent with surrounding code that also breaks it (maybe for historic reasons) -- although this is also an opportunity to clean up someone else's mess (in true XP style).
  3. Because the code in question predates the introduction of the guideline and there is no other reason to be modifying that code.
  4. When the code needs to remain compatible with older versions of Python that don't support the feature recommended by the style guide.

 

python函数的编码规范:

#驼峰命名法
printEmployeePaychecks();
def setMainFrameColor(self, color):
...
#下划线法
print_employee_pay_checks();
def set_main_frame_color(self, color):
...

https://blog.csdn.net/xHibiki/article/details/83692665

posted on 2020-10-14 17:34  喝咖啡不加糖  阅读(88)  评论(0编辑  收藏  举报