How is the original string useful in Python?
3 answers
Raw strings are typically used for regular expressions that must include a backslash.
re.match(r'\b(\w)+', string) # instead of re.match('(\\w)+', string
They are also useful for DOS file paths that would otherwise have to double each path separator.
path = r'C:\some\dir' # instead of 'C:\\some\\dir'
+7
source to share
They save you from aberrant toothpick syndrome .
a situation in which a quoted expression becomes unreadable because it contains a large number of escape characters, usually a backslash ("\")
+6
source to share