On Sat, Apr 21, 2012 at 10:51 PM, gst <g.sta...@gmail.com> wrote: > case 2) also ok to me: > >>>> x = id([]) ; y = id([]) >>>> x == y > True >>>> > > > case 3) NOT ok to me : > >>>> x = id([]) >>>> y = id([]) >>>> x == y > False >>>>
The fact that ids get reused at all is an implementation detail ONLY. In CPython, id() returns the object's memory address, but in other Python implementations, it returns something else (one (Jython??) returns a sequential number, never reused). Here's my take on the difference here. You did all of these in a single session, so by the time you got to case 3, x already contained a value (the previous integer). The allocation and deallocation of integer objects created your different behavior. I tried these from command-line Python (3.2 on Windows, fwiw), restarting the interpreter between, and got consistent results. The main thing to know, though, is that the id MAY be reused once the object is destroyed, but any reuse should be considered utterly coincidental. A Python could be completely compliant with an id implementation in which object type gets encoded into it somehow, but programs written to make use of that information would be just as vulnerable as those making use of reuse. ChrisA -- http://mail.python.org/mailman/listinfo/python-list