Python: Triple Quote String

By Xah Lee. Date: . Last updated: .

Triple Quote for Multi-Lines String

To quote a string of multiple lines, use triple quotes.

The quote character can be either

xx = """this
is
tree lines"""

print(xx)

# this
# is
# tree lines

The string can also be prefixed with r for Raw String.

xx = """aa\nbb
cc"""

print(xx)

# aa
# bb
# cc

# raw string. interpret blackslash literally
yy = r"""aa\nbb
cc"""

print(yy)

# aa\nbb
# cc

Python, String