Q about object identity
vronskij at gmail.com
vronskij at gmail.com
Tue Jun 3 17:26:04 EDT 2008
On 3. Jún, 23:08 h., Christian Heimes <li... at cheimes.de> wrote:
> vrons... at gmail.com schrieb:
>
> > Hello,
>
> > I am testing object identity.
>
> > If I do it from the interpreter, I get strange results.
>
> >>>> print [] is []
> > False
>
> >>>> print id([]), id([])
> > 3083942700 3083942700
>
> > Why is that? Isn't this an error?
>
> No, it's not an error. You are getting this result because the list
> implementation keeps a bunch of unused list objects in a free list. It's
> an optimization trick. Python has to create two different list objects
> for "[] is []" while it can reuse the same list object for id([]) == id([]).
>
> Christian
Aha.
Thanks.
jan bodnar
More information about the Python-list
mailing list