The rule of literal string

Chris Rebert clp at rebertia.com
Wed Dec 17 18:25:41 EST 2008


2008/12/17 Li Han <lihang9999 at gmail.com>:
> On 12月18日, 上午7时12分, Scott David Daniels <Scott.Dani... at Acm.Org> wrote:
> Scott wrote:
>> Try:  print repr(repr("'"))
>> that might enlighten you.
>
> I found that print( repr( repr( arbitarystring ) ) ) == repr
> ( arbitarystring )

As I stated previously, the key rule is:

eval(repr(something)) == something

That is, repr() gives a string of Python code that, when evaluated,
results in what you gave to repr().

So repr('') ==> "''"
And repr("''") ==> "\"''\""
Which when print()-ed is: "''"
And eval("''") is the same as entering two apostrophes ('') at the
REPL, both of which give an empty string object.

Cheers,
Chris

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


More information about the Python-list mailing list