Creating long strings

3.3.4. Creating long strings#

Normally, we want to avoid writing very long code lines. For instance, it is common to limit the width of a line to 80 characters.

Following this limit may be difficult when creating long strings. To this effect, we can create split a long string on multiple lines, by enclosing multiple sub-strings between parentheses.

long_string = (
    "Lorem ipsum dolor sit amet, consectetur adipiscing 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."
)

print(long_string)
Lorem ipsum dolor sit amet, consectetur adipiscing 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.