[Python-ideas] Briefer string format

Chris Angelico rosuav at gmail.com
Mon Jul 20 06:59:52 CEST 2015

On Mon, Jul 20, 2015 at 2:42 PM, Mike Miller <python-ideas at mgmiller.net> wrote:
> Thanks for thinking about it, Chris.  After several mentions of u'' and b''
> I was waiting patiently for '' and r''.  I guess r'' does nothing but what
> does '' or "" do at runtime?
>     "\tcommand line --params\n"  -->  " command line --params
> "
> It looks like there is some runtime conversion happening there, though I
> don't know the implementation details.

No, it's not runtime conversion; it's an alternative syntax. Aside
from unicode vs bytes, all types of string literals are just different
ways of embedding a string in your source code; this is why it's
sometimes important to talk about a "raw string literal" rather than
abbreviating it to "raw string", as if the string itself were

You can play around with it in the interactive interpreter. All
strings show the same form in repr, namely the unprefixed form (again,
apart from a b"..." prefix on bytes); once the compiler has turned
source code notation into constants, they're just string objects.


More information about the Python-ideas mailing list