用python的方式写多个函数?

2024-04-26 17:30:36 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我从来没见过,或者至少从来没注意过。我决定用谷歌搜索一些Python示例代码,一些图片显示的代码有两行换行符,但有些只有一行。有没有一个普遍接受的方法来解决这个问题,还是取决于用户的偏好?你知道吗


Tags: 方法函数代码用户示例错误图片pycharm
1条回答
网友
1楼 · 发布于 2024-04-26 17:30:36

这被认为是一种很好的做法。根据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代码的样式指南

相关问题 更多 >