What is ''r'' in python?

Christopher Thunes c2thunes at brewtab.com
Wed Jan 7 01:38:33 EST 2009


Hey Harish,
   Python automatically concatenates strings constants so this is 
actually '' then r'' which is the empty string followed by a 'raw' empty 
string. See here, 
http://docs.python.org/tutorial/introduction.html#strings. ''u'' and 
''b'' will work for the same reason.

- Chris

Harish Vishwanath 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?
> 
> Regards,
> Harish
> 
> 
> ------------------------------------------------------------------------
> 
> --
> http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list