How do I split the definition of a long string over multiple lines?
You can split a string over multiple lines by using triple quotes, either ''' or """ .
You can split a string over multiple lines by using triple quotes, either ''' or """ .
For example:
Split a string over multiple lines by using triple single-quotations
string = '''This is a long string
that spans multiple lines'''Or:
Split a string over multiple lines by using triple double-quotations
string = """This is a long string
that spans multiple lines"""
<div class="alert alert-info flex not-prose">![]()
<span class="hidden md:block">Watch a video course</span>Python - The Practical Guide</div>
You can also use the backslash character ( \ ) at the end of each line to achieve a similar effect:
Split a string over multiple lines using the backslash character
string = "This is a long string \
that spans multiple lines"Note that when using the backslash, there should not be any whitespace or characters after it on the same line.