In a Python script I'm looking at the string has a \ before it:
print """\
Content-Type: text/html\n
<html><body>
<p>The submited name was "%s"</p>
</body></html>
""" % name
If I remove the \ it breaks. What does it do?
A multiline string in Python begins and ends with either three single quotes or three double quotes. Any quotes, tabs, or newlines in between the “triple quotes” are considered part of the string.
Python multiline string begins and ends with either three single quotes or three double-quotes.
It tells Python to ignore the newline directly following the backslash. The resulting string starts with Content-Type:
, not with \nContent-Type:
:
>>> '''\
This is the first line.
This is the second line.
'''
'This is the first line.\nThis is the second line.\n'
>>> '''
... This is the first line.
... This is the second line.
... '''
'\nThis is the first line.\nThis is the second line.\n'
Note how the two results differ; the first has no \n
newline character at the start, the other does.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With