The order of iterable de-referencing in assignment?
Shiyao Ma
i at introo.me
Wed Aug 24 06:54:17 EDT 2016
Hi,
Given a = [1, 2]
a.extend(a) makes a = [1,2, 1,2]
One might guess a.extend(a) would turn into an infinite loop. It turns out here Python first gets all the items of `a' and then append them to `a', so the infinite loop is avoided.
My question is, is there any doc on the behavior of things like this?
Another related example might be:
a[:] = a
Hopefully Python first gets all the items on the *right* side and then assigns them to the left.
Regards.
More information about the Python-list
mailing list