[Python-ideas] Unpacking iterables for augmented assignment
Jonathan Fine
jfine2358 at gmail.com
Sat Aug 25 17:14:27 EDT 2018
Hi James
Thank you for the simple example. It makes discussing your proposal
much easier. I hope you don't mind, I'll modify it a little to make
the semantics clearer, at least to me.
Here it is.
init = (10, 20)
incr = (1, 2)
(a, b) = init
# Now, (a, b) == (10, 20)
a, b += incr
# Now (a, b) == (11, 22)
However, I'm not sure your suggestion sits well with the following
>>> (10, 20) + (1, 2)
(10, 20, 1, 2)
>>> x = [10, 20]
>>> x += [1, 2]
>>> x
[10, 20, 1, 2]
By the way, I was surprised to find that this is valid
>>> [a, b] = 1, 2
with best regards
Jonathan
More information about the Python-ideas
mailing list