How can I do a line break (line continuation) in Python?

后端 未结 11 1585
囚心锁ツ
囚心锁ツ 2020-11-21 22:56

I have a long line of code that I want to break up among multiple lines. What do I use and what is the syntax?

For example, adding a bunch of strings,



        
11条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-21 23:38

    Put a \ at the end of your line or enclose the statement in parens ( .. ). From IBM:

    b = ((i1 < 20) and
         (i2 < 30) and
         (i3 < 40))
    

    or

    b = (i1 < 20) and \
        (i2 < 30) and \
        (i3 < 40)
    

提交回复
热议问题