Raw String Question

Albert Hopkins marduk at letterboxes.org
Thu Mar 12 16:11:02 EDT 2009


> > Yep...as documented[1], "even a raw string cannot end in an odd number 
> > of backslashes".
> 
> So how do you explain this?
> 
>      >>> r'a\'b'
>      "a\\'b"

That doesn't "end in an odd number of backslashes."

Python is __repr__esenting a raw string as a "regular" string.
Literally they are equivalent:

>>> a = r'a\'b'
>>> b = "a\\'b"
>>> a
"a\\'b"
>>> b
"a\\'b"
>>> print a
a\'b
>>> print b
a\'b
>>> a == b
True





More information about the Python-list mailing list