Python: Raw String

A Python raw string is a normal string, prefixed with a r or R.

This treats characters such as backslash (‘\’) as a literal character. This also means that this character will not be treated as a escape character.

This is useful when we want to have a string that contains backslash and don’t want it to be treated as an escape character.

Example:

raw_s = r'Hi\nHello'
print(raw_s)

Output: Hi\nHello

Tags