How to declare a long string in Python?

前端 未结 4 1194
生来不讨喜
生来不讨喜 2020-12-04 19:06

I have a really long string in python:

long_string = \'
this is a really
really
really
long
string
\'

However, since the string spans multi

4条回答
  •  攒了一身酷
    2020-12-04 19:52

    You can also do this, which is nice because you have better control over the whitespace inside of the string:

    long_string = (
        'Lorem ipsum dolor sit amet, consectetur adipisicing elit, '
        'sed do eiusmod tempor incididunt ut labore et dolore magna '
        'aliqua. Ut enim ad minim veniam, quis nostrud exercitation '
        'ullamco laboris nisi ut aliquip ex ea commodo consequat. '
        'Duis aute irure dolor in reprehenderit in voluptate velit '
        'esse cillum dolore eu fugiat nulla pariatur. Excepteur sint '
        'occaecat cupidatat non proident, sunt in culpa qui officia '
        'deserunt mollit anim id est laborum.'
    )
    

提交回复
热议问题