__iadd__ and fellows missing (Python 2.2)
Carey Evans
careye at spamcop.net
Sat Apr 13 19:39:07 EDT 2002
On Sun, 14 Apr 2002 09:53:56 +1200, quoth Ralf Juengling,
> Can anybody explain why the special method 'i.__iadd__' does not exist,
> while 'i+=1' is a legal expression ('i' being a int)?
In the absence of __iadd__, += uses __add__ instead. The end result is
similar to:
try:
iadd = x.__iadd__
except AttributeError:
iadd = x.__add__
x = iadd(y)
There's a bit more logic to enable addition of different types (e.g. int
with float) which is described in the reference manual at:
http://www.python.org/doc/current/ref/numeric-types.html
--
Carey Evans http://home.clear.net.nz/pages/c.evans/
Cave canem.
More information about the Python-list
mailing list