Newbie question - what is the 'r' operator?
Thomas A. Bryan
tbryan at python.net
Mon Feb 7 19:17:40 EST 2000
Craig Findlay wrote:
>
> This is probably obvious but ...
>
> I have seen example code where an 'r' prefix is used in from of a
> string, eg r'mystring'
>
> What does it do, I can't seem to locate any documentation about it.
> Thanks in advance for any help.
It indicates a raw string.
>>> s1 = 'a \normal \tstring\012example'
>>> print s1
a
ormal string
example
>>> s2 = r'a \normal \tstring\012example'
>>> print s2
a \normal \tstring\012example
I'm not sure of the formal definition of a raw string. It may
simply escape all of the backslashes. For example,
>>> s1
'a \012ormal \011string\012example'
>>> s2
'a \\normal \\tstring\\012example'
Thus, \t won't be interpreted as a tab in a raw string.
great-for-regular-expressions-and-win32-paths-ly yours
---Tom
More information about the Python-list
mailing list