Python: Raw String

Profile picture for user devanshi.srivastava
Submitted by devanshi.srivastava on

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.


raw_s = r'Hi\nHello'

Output: Hi\nHello