inconsistency with += between different types ?

Andreas Leitgeb Andreas.Leitgeb at siemens.at
Mon Aug 5 18:10:17 CEST 2002


The following snippet demonstrates it:

--- snip ---
def f(x,y): x+=y

d='foo';     f(d,'bar');   print d    #  ->  'foo'
i=4;         f(i,2);       print i    #  ->  4
#but:
l=[1,2,3];   f(l,[7,8,9]); print l    #  ->  [1, 2, 3, 7, 8, 9]
--- snip ---
 
It seems that  lists are the only type, where the changes get visible
outside, although I'd have expected all types to behave as lists do.

I've not tried other extended-assignment(*)-operators *=,-=,...=, yet.

The question seems to be:
  Is an extended assignment(*) a "modification" of an object or
  a re-assignment to the left-side operand ?

Is it just a question of whether and how __iadd__ is implemented,
or is there some deeper meaning in this ?
Is it a bug ?  

(*) "extended assignment" is supposed to be the back-translation of
  "erweiterte Zuweisung", as it is called in my german-language book
  about python.

PS: I checked it with  2.2.0 & 2.0.0   (1.5 didn't have += yet)

-- 
Newsflash: Sproingy made it to the ground !
  read more ... <http://avl.enemy.org/sproingy/>



More information about the Python-list mailing list