编写多个函数的 Pythonic 方式?

Pythonic way of writing multiple functions?

我已经编写 Python 代码大约 3-4 个月了。我通常用 Atom 编写,但最近在看到它的许多优点后决定尝试 PyCharm。在编写一些函数时,我注意到我遇到了错误,但我不知道为什么。根据 PyCharm,函数后面应该有两个换行符?

我从来没有见过这个,或者至少以前从来没有注意到过。我决定 Google 一些示例 Python 代码,一些图片显示代码有两个换行符,但有些只有一个。是否有一种普遍接受的方式来解决这个问题,还是取决于用户偏好?

这被认为是一种很好的做法。根据 PEP-0008 document:

Surround top-level function and class definitions with two blank lines.

Method definitions inside a class are surrounded by a single blank line.

Extra blank lines may be used (sparingly) to separate groups of related functions. Blank lines may be omitted between a bunch of related one-liners (e.g. a set of dummy implementations).

Use blank lines in functions, sparingly, to indicate logical sections.

PEP-8 是 Python 代码

的风格指南