3 ms·
> list object is constructed once and assigned to both variables Ummm no the list is constructed once and assigned to b and then b is assigned to a. It would b
by mathisfun123 8mo ago
> list object is constructed once and assigned to both variables
Ummm no the list is constructed once and assigned to b and then b is assigned to a. It would be crazy semantics if `a = b = ...` meant `a` was assigned `...`.
Edit: I'm wrong it's left to right not right to left, which makes the complaint in the article even dumber.
- ayhanfuat 8mo ago> then b is assigned to a Wouldn't that require a LOAD_FAST? Also a is assigned first (from left to right) so a = ... happens either way.
- kccqzy 8mo agoIt’s assigned left to right, not right to left. It’s documented in the Python language reference. > An assignment statement evaluates the expression list and assigns the single resulting object to each of the target lists, from left to right. Consider this: a = [1, 2] i = a[i] = 1 If assignment were to happen right to left, you would get a NameError exception because the first assignment would require an unbound variable.
- mathisfun123 8mo agoFine but that even moreso illustrates how goofy the expectation that the "ctor" for [] would be called twice.