Compound Assignment Operators ( +=, *=, etc...)

A.M. Kuchling amk at mira.erols.com
Sun Aug 15 10:52:21 EDT 1999


On Sun, 15 Aug 1999 03:09:14 -0500, Andrew McDowell <drew at getaway.net> wrote:
>Why would you confuse x += y (which would seem to imply the former) to mean
>x.extend(y) ?   It _is_ an assignment statement after all..

If you have:
aList = []
bList = aList
aList += [1,2,3]

Do aList and bList still point to the same list?  I think people could
argue for either interpretation as being the most intuitive.

Another thing: if the meaning is taken as "x = x + y", this means that
x+=y is really quite inefficient, which will be confusing to people
who've been indoctrinated to believe that '++' lets the compiler
produce better code.  That may be true for C, but if you coded "for i
in biglist: resultlist += thingy", you'd do a lot of unnecessary list
copying.  

-- 
A.M. Kuchling			http://starship.python.net/crew/amk/
We are Brigand Philosophers / Our hearts are high and cheery, / For we know
our robbery rests upon / A sound economic theory!
    -- _The Golden Ass_, music Randolph Peters, libretto Robertson Davies





More information about the Python-list mailing list