Why is this?

John Hazen john at hazen.net
Thu Aug 11 19:10:08 EDT 2005


> >>>> [[]]*2
> > [[], []]
> >>>> [[], []] == [[]]*2
> > True
> 
> Same effect. But try the 'is' operator, to see if they are actually the  
> same instances of 'empty list':
> 
> >>>> [[], []] is [[]]*2
> > True

Just curious, did you actually cut and paste this from a real
interactive session?  (I think not.)  My interpreter (yes, I know it's
old) gives:

 $ python
 Python 2.3 (#1, Sep 13 2003, 00:49:11) 
 [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
 Type "help", "copyright", "credits" or "license" for more information.
 >>> [[], []] is [[]]*2
 False

Which is, I think, the point you were trying to make.

-John



More information about the Python-list mailing list