Why not a, b += i, j? (augmented assignment via tuple unpacking)
Steven Rumbalski
srumbalski at prodigy.net
Wed Nov 27 10:59:58 EST 2002
Joshua Marshall wrote:
> John Roth <johnroth at ameritech.net> wrote:
>
>> I'd think it would be equivalent to:
>
>> a += i
>> b += j
>
>> the corner case you mention should behave
>> the same as
>
>> a, b = b, a
>
>> Why make it more complicated than it has
>> to be?
>
> Because if you do the translation with your rule, you get:
>
> a += b
> b += a
>
> which is, in my opinion, unexpected.
Consider this:
a, b = b, a
If you do the translation with your rule, you get:
a = b
b = a
which is wrong.
So if
a, b += b, a
is unintuitive, then so is
a, b = b, a
While I think both constructs are unintuitive (especially for people coming
from other languages), I beleive that once one construct is learned the
other is natural (however this thread has certainly challenged that
assertion).
But don't get me wrong. I'm not proposing that Python be modified to
support "a, b += i, j". I just wanted to know why what felt natural to me
while using Python isn't legal Python. I suppose the possible reasons are:
1. It's not that useful, and therefore not worth implementing.
2. It's not intuitive.
3. It is intuitive, but it would be an ugly hack to implement.
4. No one has really thought of it. (Likely because it's not that useful).
Steven Rumbalski
More information about the Python-list
mailing list