Problem with assignment. Python error or mine?
Kirill Balunov
kirillbalunov at gmail.com
Thu Dec 21 14:29:16 EST 2017
2017-12-21 22:06 GMT+03:00 John Ladasky <john_ladasky at sbcglobal.net>:
> 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:
>
No copy means no copy, it is the rule! What you see is really new binding
operation under the hood.
'x=1; x += 1', means calculate x+1 and bind it to the same name. Compare it
to this example:
>>> tpl = ((1,2),(3,4))
>>> tpl += ((1,2),)
>>> tpl
((1, 2), (3, 4), (1, 2))
No copy, new binding to the same name :)
With kind regards, -gdg
More information about the Python-list
mailing list