The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. Long lines can be broken over multiple lines by wrapping expressions in parentheses. These should be used in preference to using a backslash for line continuation.
只有当反斜杠会导致语法问题或使用括号(例如with和assert语句)时才会使用反斜杠。e、 g
with something('foo') as some_name, \
something_else('bar') as some_other_name:
The preferred way of wrapping long lines is by using Python's implied
line continuation inside parentheses, brackets and braces. Long lines
can be broken over multiple lines by wrapping expressions in
parentheses. These should be used in preference to using a backslash
for line continuation.
Backslashes may still be appropriate at times. For example, long, multiple with-statements
cannot use implicit continuation, so backslashes are acceptable.
根据PEP8:
只有当反斜杠会导致语法问题或使用括号(例如
with
和assert
语句)时才会使用反斜杠。e、 g应优先于:
^{pr2}$PEP似乎更喜欢用圆括号而不是反斜杠,在这种情况下,考虑到行中没有其他圆括号使其更加混乱,我建议使用括号而不是反斜杠。在
1优先。引用神的话,又名PEP8:
即使对于
import
,PEP 328也添加了括号形式,如比…漂亮
^{pr2}$相关问题 更多 >
编程相关推荐