By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,264 Members | 1,743 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,264 IT Pros & Developers. It's quick & easy.

Difference: __iadd__ and __add__

P: n/a
Can someone please explain or point me to articles regarding these two
methods?

Thanks.
Feb 17 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
__add__ is called for the + operator
__iadd__ is called for the += operator
if __iadd__ doesnt exist, fallbacks to __add__

you know what they say for such things: rtfm.

Feb 18 '06 #2

P: n/a
I would like to point out that it isn't entirely obvious where to find
documentation for this particular thing. I know from experience where
to go, but I remember spending a long time trying to hunt this down.

For reference, you may want to check out the index of the language
reference manual.

http://www.python.org/doc/2.4.2/ref/genindex.html

Feb 18 '06 #3

P: n/a
Jonathan Gardner wrote:
I would like to point out that it isn't entirely obvious where to find
documentation for this particular thing. I know from experience where
to go, but I remember spending a long time trying to hunt this down.
I'd like to point out it should be obvious, at least as far as going to
http://docs.python.org and typing "__iadd__" into the Search field in
the upper right should be an obvious first step...
For reference, you may want to check out the index of the language
reference manual.

http://www.python.org/doc/2.4.2/ref/genindex.html


That one is the second hit in those results...

(It does seem to require reading a few of those pages to learn enough to
answer the original question. To be fair, I didn't find (in a few
minutes) any page that explicitly states what to*********@gmail.com
said, about += falling back to __add__ if __iadd__ is not defined,
though I didn't try searching for it directly.)

-Peter

Feb 18 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.