list vs tuple

Bruce Sass bsass at freenet.edmonton.ab.ca
Sat Mar 31 17:32:43 EST 2001


On Sat, 31 Mar 2001, deadmeat wrote:

> > THERE IS NO DIFFERENCE.
>
> What happens to the objects is not the point, what happens to what I put
> into a and b is the point.
>

line by line...

> >>> a = 1

"a" points to "1"

> >>> b = a

"b" points to the same thing "a" points to, not to "a" itself

> >>> a = 2

"a" now points to "2"...

> >>> b
> 1

...and "b" still points to "1"

> >>> a = [1,2,3]

"a" points to the object with the representation "[1,2,3]"

> >>> b = a

"b" points to the same object "a" points to

> >>> a[0] = 0

this modifies the first item in the sequence (or mapping) "a" points
to...

> >>> b
> [0, 2, 3]

...and since "b" points to the same object, you can see the change via
the reference from "b"

> Are you saying there is no difference (IN THE *RESULT*) between these?

Of course there is... but why should playing with references to
multiple objects have the same result as mutating a single object with
multiple references?

> Are
> you able to read?

I'm sure other are wondering the same of you (since the mindset you
need to get into has been explained, a few times)...

> What goes on in the background is NOT THE POINT. I only care about the
> values I put into them, and what happens after b = a.

...there is the way it is, and the way you think it is.  What goes on
in the background is the point, because that is how the language
works.  You may only care about what the values are, but you need to
do so within the context of the language you are using.  If the
language defines "this = that" as operating on namespaces only, then
it is best to start thinking like that (instead of thinking that it
does something with data).


- Bruce





More information about the Python-list mailing list