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

后端 未结 11 1830
囚心锁ツ
囚心锁ツ 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:41

    The danger in using a backslash to end a line is that if whitespace is added after the backslash (which, of course, is very hard to see), the backslash is no longer doing what you thought it was.

    See Python Idioms and Anti-Idioms (for Python 2 or Python 3) for more.

提交回复
热议问题