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

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

    It may not be the Pythonic way, but I generally use a list with the join function for writing a long string, like SQL queries:

    query = " ".join([
        'SELECT * FROM "TableName"',
        'WHERE "SomeColumn1"=VALUE',
        'ORDER BY "SomeColumn2"',
        'LIMIT 5;'
    ])
    

提交回复
热议问题