3.3.3. Creating strings using triple-quotes#

Python provides another type string delimiter: the triple-quote. A string defined using triple-quotes can integrate both single and double quotes in a same string without using backslash. Line breaks are also saved in the string.

s1 = """I didn't write "E = mc2", that's Einstein's thing."""

print(s1)
I didn't write "E = mc2", that's Einstein's thing.

The most common use for triple-quotes are docstrings, which will be seen later.

s2 = """I ate your sandwich.
It was good."""

print(s2)
I ate your sandwich.
It was good.