list vs tuple

Bruce Sass bsass at freenet.edmonton.ab.ca
Sat Mar 31 15:51:51 EST 2001


On Sat, 31 Mar 2001, deadmeat wrote:

> > - There is an difference between "copy" and "deep copy". What happens if
> > you make copy a structure that contains pointers in it?
>
> then you got a problem :)
>
> but thats not the point - which when the statement a = b copies the data
> across for one type it's expected to do it for others.  It doesn't, so it's
> inconsistant, contrary to the original claim.

But that is not what is happening!

	a = 1

points "a" to an object
(which just happens to have the name "1" and an integer value of 1)

	b = a

points "b" to the same object "a" points to (not to "a" itself)

	a = 2

points "a" to a different object,
but "b" is unaffected because the only relationship it has with "a"
is/was the fleeting one of having referred to the same object at some
point during the program's execution.

You seem to be thinking of "a = 1" as a statement which creates an
integer object with the value of 1 and the name "a", when it is
actually just creating a pointer labeled "a" to an object whose value
is int(1).  It may seem subtle, but it is a big distinction, and is
why your int vs list example a few posts back was flawed... in the
first case (integers)  you were changing what objects the labels were
refering to, in the second example (lists) you were modifying the
contents of an object referred to by more than one label -- apples and
oranges, eh.

HTH


- Bruce





More information about the Python-list mailing list