On Sat, 21 Apr 2012 04:25:36 +0100
Rotwang <sg...@hotmail.co.uk> wrote:

> On 21/04/2012 01:01, Roy Smith wrote:
> > In article<877gxajit0....@dpt-info.u-strasbg.fr>,
> >   Alain Ketterlin<al...@dpt-info.u-strasbg.fr>  wrote:
> >
> >> Tuples are immutable, while lists are not.
> >
> > If you really want to have fun, consider this classic paradox:
> >
> >>>> [] is []
> > False
> >>>> id([]) == id([])
> > True
> 
> Huh. This is not what I would have expected. What gives?
> 

I'm just guessing here, but as id is "is guaranteed to be unique among
simultaneously existing objects", the list literals on each side of the
comparison do not simultaneously exist; presumably the first one is created,
id'ed, then garbage collected (as it is not named), then the other one is
created and gets the same id just freed up by the first one.

OTOH, "is" hangs on to both objects in order to compare them.

c.f.:

>>> l, m = [], []
>>> id(l) == id(m)
False
  

Is that right?

--
John 
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to