Problem with assigning variables of type List

Michael Hudson mwh at python.net
Mon Aug 19 07:19:15 EDT 2002


abhishek at ocf.berkeley.edu (Abhishek Roy) writes:

> Hello,
>       It appears that, 
> a = b = []
> is not the same as
> a=[]
> b=[]
> 
> because in the previous case a and b will refer to the same list eg,
> >>> b.append(23)
> >>> a
> [23]
> I am completely baffled by this. Can someone please explain?

You could read this:

   http://starship.python.net/crew/mwh/hacks/objectthink.html

Cheers,
M.

-- 
  ARTHUR:  Why should a rock hum?
    FORD:  Maybe it feels good about being a rock.
                    -- The Hitch-Hikers Guide to the Galaxy, Episode 8



More information about the Python-list mailing list