Augmented Assignment question

Mel Wilson mwilson at the-wire.com
Wed Jul 16 23:01:23 CEST 2003


In article <20030716132455272-0600 at news.xmission.com>,
Adam Ruth <owski at hotmail.com> wrote:
>As a side note, I wouldn't have thought that the augmented assign would
>work the way you tried to use it.  I would have thought that it would be
>analagous to the + operator and sequences:
>
>>	x = [1,2,3]
>>	y = [1,2,3]
>>	x + y
>[1,2,3,1,2,3]
>
>So that the agumented form would be:
>
>>	x = [1,2,3]
>>	x += [1,2,3]
>[1,2,3,1,2,3]
>
>But I've never tried it before and didn't know that it didn't work with
>sequences.  You learn something new every day.

It does:

>>> def multi():
...     return 4, 5, 6
...
>>> a = (1,2,3)
>>> a += multi()
>>> a
(1, 2, 3, 4, 5, 6)

It seems to be just that += refuses to work with tuple unpacking.

        Regards.        Mel.




More information about the Python-list mailing list