decouple copy of a list

Ben Finney ben+python at benfinney.id.au
Fri Dec 10 15:23:49 EST 2010


Dirk Nachbar <dirknbr at gmail.com> writes:

> I want to take a copy of a list a
>
> b=a

In addition to the other good replies you've received:

To take a copy of an object, the answer is never ‘b = a’. That binds a
reference ‘b’ to the same object referenced by ‘a’.

The assignment operator ‘=’ never copies; it binds a reference to an
existing object.

To create a copy, you always need to do something other than assignment.

Hope that keeps it clear for you.

-- 
 \          “Computer perspective on Moore's Law: Human effort becomes |
  `\           twice as expensive roughly every two years.” —anonymous |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list