Ayo,
On 11/18/2013 01:57 AM, Ayo Rotibi wrote:
I read that an assignment with an = on lists does not make a copy.
Instead, assignment makes the two variables point to the one list in
memory. For instance, if a = [1, 2, 3] and b=a, then b = [1, 2, 3].
However, I discovered that if I change the value in ‘a’, ‘b’ does not
take the new value. I thought since it is pointing to the same
storage as ‘a’, ‘b’ should take the new value…
It is not clear to me what code you are running, maybe you could give us
the specifics? When I run an assignment like you seem to be talking
about I get the expected result (using ipython for an interactive
session to demonstrate):
In [1]: a=[1,2,3]
In [2]: b=a
In [3]: b
Out[3]: [1, 2, 3]
In [4]: a[1]=0
In [5]: a
Out[5]: [1, 0, 3]
In [6]: b
Out[6]: [1, 0, 3]
Is that not what you are seeing? If not perhaps you could show us how
you are doing the list assignment and changing the list a, what output
you are expecting and what output you are getting.
thomas
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor