<p>当(B)将超过最大行长度时(A)<a href="https://www.python.org/dev/peps/pep-0008/#indentation" rel="nofollow noreferrer"><strong>Vertical Alignment</strong></a>将被使用,有时即使不会-为了更好的可读性。在</p>
<p>以下是该页的前3个示例:</p>
<blockquote>
<p>Yes:</p>
<pre><code># Aligned with opening delimiter.
foo = long_function_name(var_one, var_two,
var_three, var_four)
# More indentation included to distinguish this from the rest.
def long_function_name(
var_one, var_two, var_three,
var_four):
print(var_one)
# Hanging indents should add a level.
foo = long_function_name(
var_one, var_two,
var_three, var_four)
</code></pre>
</blockquote>
<p>您询问的是上面第一个示例的<strong>变体,为了清晰起见,每行只有一个arg</strong>。在</p>
<blockquote>
<p>No:</p>
<pre><code># Arguments on first line forbidden when not using vertical alignment.
foo = long_function_name(var_one, var_two,
var_three, var_four)
</code></pre>
</blockquote>
<p>和(C),使用给定名称的参数(关键字参数)完成,这样您就不需要查找被调用函数中的参数了。通常,每个可能充当被调用函数核心功能的标志或修饰符的不明显的参数都应作为关键字参数传递。例如:</p>
<pre><code>> read_file('abc.txt', 1024, True) # yes, you know 'abc.txt' is the filename
> # What are the 1024 and True for?
> # versus...
> read_file('abc.txt', max_lines=1024, output_as_list=True) # now you know what it does.
</code></pre>
<p>注:<a href="https://stackoverflow.com/a/34192044/1431750">The answer by @falsetru</a>没有错。最大行长度是重新格式化代码的第一个原因。至于为什么要这样对齐,那就是垂直对齐。在</p>