User-defined augmented assignment

Pierre Barbier de Reuille pierre.barbier at cirad.fr
Thu Sep 29 10:08:58 EDT 2005


Reinhold Birkenfeld a écrit :
> Pierre Barbier de Reuille wrote:
> 
> 
>>So, what I would suggest is to drop the user-defined augmented
>>assignment and to ensure this equivalence :
>>
>>a X= b <=> a = a X b
>>
>>with 'X' begin one of the operators.
> 
> 
> It can be done, but it's unnecessary for mutable objects like
> sets or lists. A new object must be created in these cases where
> one would suffice.

Well, my point is: the benefit is too small compared to the
disadvantage. If you really have a mutable (let say a list with +=) then
you do:

>>> a.extend(b)

and there is no interpretation error possible. BTW, that's what's done
in the standard library ...

Pierre

> 
> Reinhold



More information about the Python-list mailing list