右括号的缩进 [英] Indentation of closing parenthesis
问题描述
我相信PEP8风格指南说,
I believe the PEP8 style guide says that both
some_kind_of_list = [
1, 2, 3,
4, 5, 6
]
def function_that_takes_long_arguments(
long_argument_1,
long_argument_2
):
return long_argument_1
和
some_kind_of_list = [
1, 2, 3,
4, 5, 6
]
def function_that_takes_long_arguments(
long_argument_1,
long_argument_2
):
return long_argument_1
使用一个或另一个,例如,如果我以后在我的生活移动到C ++?
are acceptable, but does it make sense to use one or the other, e.g., if I move onto C++ later on in my life?
EDIT
对于一个函数,PEP8风格指南实际上是这样说的:
Apologies, for a function, the PEP8 style guide actually says something like:
something = function_that_takes_long_arguments(
long_argument_1,
long_argument_2
)
推荐答案
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.
这篇关于右括号的缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!