The rule of literal string

Chris Rebert clp at
Thu Dec 18 00:25:41 CET 2008

2008/12/17 Li Han <lihang9999 at>:
> 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.


Follow the path of the Iguana...

More information about the Python-list mailing list