The rule of literal string

Chris Rebert clp at rebertia.com
Thu Dec 18 01:06:35 CET 2008


On Wed, Dec 17, 2008 at 3:52 PM, Li Han <lihang9999 at gmail.com> wrote:
> Chris worte:
> [snip]
>> 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.
>
> On my machine:
>>>> repr("''")
> '"\'\'"'
> Han

Well, I was kinda winging it and didn't actually use the interpreter
for some of those. The point is that the output I gave _could_
reasonably be that of the interpreter (if the implementation details
of repr() were slightly different; it would still meet the spec
anyway) and illustrates the eval()-repr() relationship.

Just keep in mind the equivalence rule and what repr() does should
become obvious.

Cheers,
Chris

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



More information about the Python-list mailing list