Pythonic way to create a long multi-line string

后端 未结 27 1705
滥情空心
滥情空心 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:00

    Use triple quotation marks. People often use these to create docstrings at the start of programs to explain their purpose and other information relevant to its creation. People also use these in functions to explain the purpose and application of functions. Example:

    '''
    Filename: practice.py
    File creator: me
    File purpose: explain triple quotes
    '''
    
    
    def example():
        """This prints a string that occupies multiple lines!!"""
        print("""
        This
        is 
        a multi-line
        string!
        """)
    

提交回复
热议问题