Pythonic way to create a long multi-line string

后端 未结 27 1678
滥情空心
滥情空心 2020-11-22 00:47

I have a very long query. I would like to split it in several lines in Python. A way to do it in JavaScript would be using several sentences and joining them with a +<

27条回答
  •  悲&欢浪女
    2020-11-22 01:14

    Another option that I think is more readable when the code (e.g variable) is indented and the output string should be a one liner (no newlines):

    def some_method():
    
        long_string = """
    a presumptuous long string 
    which looks a bit nicer 
    in a text editor when
    written over multiple lines
    """.strip('\n').replace('\n', ' ')
    
        return long_string 
    

提交回复
热议问题