Python: Raw String (r-prefix)

By Xah Lee. Date: . Last updated: .

Raw string

r or R in front of the string quote means backslash characters do not have special meaning. i.e. String Escape Sequence has no special interpretation.

🛑 WARNING: Despite the fact that backslash has no special meaning in raw string, but raw string cannot end with a single backslash. This is due to string syntax design flaw.

xx = r"this \n and that"

print(xx)
# prints
# this \n and that

# the backslash n do not have special meaning
# raw string with triple quote

xx = r"""this
and \n that"""

print(xx)

# this
# and \n that

Python, String