%r

Fredrik Lundh fredrik at pythonware.com
Mon Mar 6 12:24:42 EST 2006


"Blackbird" <fake at nospam.no> wrote:

> >> [...]
> >
> >>>> 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'
>
> Excellent counterexample.  Can something like this happen for other things
> than quotes?

>>> a = '\377'
>>> print '%r' % a
'\xff'
>>> a = r'\377'
>>> print "'%s'" % a
'\377'

I still recommend looking up %s and %r and str() and repr() in the
documentation.  it's not hard to understand what they do, and that
approach works a bit better than cargo cult programming.

</F>






More information about the Python-list mailing list