The preferred way of wrapping long
lines is by using Python's implied
line continuation inside parentheses, brackets and braces. If necessary,
you can add an extra pair of parentheses around an expression, but
sometimes using a backslash looks better. Make sure to indent the continued line
appropriately. The preferred place to break around a binary
operator is after the operator, not before it.
The preferred way of wrapping long lines is by using Python's implied line
continuation inside parentheses, brackets and braces. If necessary, you
can add an extra pair of parentheses around an expression, but sometimes
using a backslash looks better. Make sure to indent the continued line
appropriately.
隐式行继续的示例:
a = some_function(
'1' + '2' + '3' - '4')
关于二进制运算符周围换行的主题,它接着说:
For decades the recommended style was to break after binary operators.
But this can hurt readability in two ways: the operators tend to get scattered across different columns on the screen, and each operator is moved away from its operand and onto the previous line.
In Python code, it is permissible to break before or after a binary operator, as long as the convention is consistent locally. For new code Knuth's style (line breaks before the operator) is suggested.
有不止一种方法。
1)。长篇大论:
(第二章)。使用括号:
(第三章)。再次使用
\
:引用PEP8:
如果要将长str赋给变量,可以执行以下操作:
不要添加任何逗号,否则将得到一个包含许多str的元组!
来自PEP 8 - Style Guide for Python Code:
隐式行继续的示例:
关于二进制运算符周围换行的主题,它接着说:
显式行继续的示例:
相关问题 更多 >
编程相关推荐