What is ''r'' in python?

Chris Rebert clp2 at rebertia.com
Wed Jan 7 01:45:51 EST 2009


On Tue, Jan 6, 2009 at 10:28 PM, Harish Vishwanath
<harish.shastry at gmail.com> wrote:
> Hello,
>
> I accidentally did this in the shell.
>
>>>> ''r''
> ''
>>>> ''r'' == ''
> True
>>>> ''r'' == ""
> True
>
> That is <singlequote singlequote r singlequote singlequote>. However if I
> try ->
>
>>>> ''c''
>   File "<stdin>", line 1
>     ''c''
>       ^
> SyntaxError: invalid syntax
>>>> ''z''
>   File "<stdin>", line 1
>     ''z''
>       ^
> SyntaxError: invalid syntax
>
> Any other character that way is Invalid Syntax. What is so special about
> character r enclose within a pair of single quotes?

That's probably an artifact of r being used as the prefix in the
syntax for raw strings. See
http://docs.python.org/reference/lexical_analysis.html#string-literals
for more on raw strings.

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com



More information about the Python-list mailing list