__iadd__ and fellows missing (Python 2.2)

Ralf Juengling juenglin at informatik.uni-freiburg.de
Sat Apr 13 17:53:56 EDT 2002


"Terry Reedy" <tejarex at yahoo.com> writes:

> > I understand now, that 'i+=1' is no real in-place operation
> 
> Nor is it a false in-place operation :<)
> 
> > but  just a shortcut for 'i=i+1' since int is immutable.
> 
> Correct.  This is true for all immutable types.
> 
> > For the sake of clarity, an 'in-place' operation should really
> > work in-place, don't you think?
> 
> Yes, but +=, etc, are not in-place operations, and are not advertised
> as such.
> 

Michael's answer to my initial mail suggested that __iadd__ stands
for an in-place version of add:

>> Shouldn't I find the special methods '__iadd__' et al, when
>> asking for the attributes of 'int'?
>
>ints are immutable, so they don't implement __iadd__.  lists 

I'm well confused now... 
Can anybody explain why the special method 'i.__iadd__' does not 
exist, while 'i+=1' is a legal expression ('i' being a int)?

Thanks so far,
Ralf





More information about the Python-list mailing list