且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Python中进行换行(换行)?

更新时间:2022-10-31 15:49:33

哪一行?您只需在下一行就有参数就可以了,没有任何问题:

What is the line? You can just have arguments on the next line without any problems:

a = dostuff(blahblah1, blahblah2, blahblah3, blahblah4, blahblah5, 
            blahblah6, blahblah7)

否则,您可以执行以下操作:

Otherwise you can do something like this:

if a == True and \
   b == False

查看样式指南以获取更多信息.

在您的示例行中:

a = '1' + '2' + '3' + \
    '4' + '5'

或者:

a = ('1' + '2' + '3' +
    '4' + '5')

请注意,样式指南指出,***使用带括号的隐式连续,但是在这种特殊情况下,仅在表达式周围加上括号可能是错误的方法.

Note that the style guide says that using the implicit continuation with parentheses is preferred, but in this particular case just adding parentheses around your expression is probably the wrong way to go.