# 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)
您询问的是上面第一个示例的变体,为了清晰起见,每行只有一个arg。在
No:
# Arguments on first line forbidden when not using vertical alignment.
foo = long_function_name(var_one, var_two,
var_three, var_four)
> 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.
^{} :如果不拆分为多行,则行长度将超过79个字符。在
当(B)将超过最大行长度时(A)Vertical Alignment将被使用,有时即使不会-为了更好的可读性。在
以下是该页的前3个示例:
您询问的是上面第一个示例的变体,为了清晰起见,每行只有一个arg。在
和(C),使用给定名称的参数(关键字参数)完成,这样您就不需要查找被调用函数中的参数了。通常,每个可能充当被调用函数核心功能的标志或修饰符的不明显的参数都应作为关键字参数传递。例如:
注:The answer by @falsetru没有错。最大行长度是重新格式化代码的第一个原因。至于为什么要这样对齐,那就是垂直对齐。在
相关问题 更多 >
编程相关推荐