%r

Duncan Booth duncan.booth at invalid.invalid
Mon Mar 6 11:51:22 EST 2006


Blackbird wrote:

> I'm trying to get a complete grip on %r.  Is it true that the two
> programs 
> 
> a = '*anything the parser accepts*'
> print '%r' % a
> 
> vs.
> 
> a = r'*anything the parser accepts*'
> print "'%s'" % a
> 
> always produce the same output, where *anything the parser accepts*
> can be replaced with, well, anything the parser accepts?

>>> a = 'I don\'t think so'
>>> print '%r' % a
"I don't think so"
>>> a = r'I don\'t think so'
>>> print "'%s'" % a
'I don\'t think so'



More information about the Python-list mailing list