Problem with assignment. Python error or mine?
John Ladasky
john_ladasky at sbcglobal.net
Thu Dec 21 14:06:49 EST 2017
On Thursday, December 21, 2017 at 7:37:39 AM UTC-8, MRAB wrote:
> Python never makes a copy unless you ask it to.
>
> What x1=X does is make the name x1 refer to the same object that X
> refers to. No copying.
Well, except with very simple, mutable data types like scalars... compare this:
>>> x=5
>>> y=x
>>> x,y
(5, 5)
>>> x+=1
>>> x,y
(6, 5)
To this:
>>> a=[1,2,3]
>>> b=a
>>> a,b
([1, 2, 3], [1, 2, 3])
>>> a[1]=9
>>> a,b
([1, 9, 3], [1, 9, 3])
More information about the Python-list
mailing list