更新时间:2022-12-27 18:28:51
pep8
python style
pep8
python style guide checker doesn't think both snippets are acceptable.
第一个选项:
$ pep8 test_pep.py
test_pep.py:10:5: E125 continuation line with same indent as next logical line
第二个选项(无警告):
Second option (no warnings):
$ pep8 test_pep.py
$
如您所见,对于列表,可以同时使用。但是对于函数,第二种方法是优选的,因为在第一个片段中,函数体缩进为前一行,并且对可读性产生负面影响。
As you see, for the list it is okay to use both. But for the function, the second approach is preferred since in the first snippet the function body is indented as the previous line and it makes a negative impact on the readability.