一只萌萌小番薯
代码风格问题.PEP8 中指出:
Continuation lines should align wrapped elements either vertically using Python's implicit line joining inside parentheses, brackets and braces, or using a hanging indent [7]. When using a hanging indent the following should be considered; there should be no arguments on the first line and further indentation should be used to clearly distinguish itself as a continuation line.
也就是说在括号内的参数很多的时候, 为了满足每一行的字符不超过79个字符, 需要将参数换行编写, 这个时候换行的参数应该与上一行的括号对齐.或者将所有参数换行编写, 此时第一行不能有参数, 即第一行的最后一个字符一定要是(, 换行后需要有一个缩进. 类似的规则也用在[], {}上.例子:
# Aligned with opening delimiter.
foo = long_function_name(var_one, var_two,
var_three, var_four)
# Hanging indents should add a level.
foo = long_function_name(
var_one, var_two,
var_three, var_four)