473,320 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Difference: __iadd__ and __add__

Can someone please explain or point me to articles regarding these two
methods?

Thanks.
Feb 17 '06 #1
3 5642
__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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jan Kokoska | last post by:
Hello, I need to recognize 'var' and , usually I would use: if a.__class__() == '': #string elif a.__class__() == : #list But unfortunately in Zope PythonScripts, where I need to use...
3
by: SeeBelow | last post by:
between this: name = "C" and this: name = StringVar() name.set("C") I hope someone can explain that to me.
21
by: Paul Rubin | last post by:
I've always found the string-building idiom temp_list = for x in various_pieces_of_output(): v = go_figure_out_some_string() temp_list.append(v) final_string = ''.join(temp_list) ...
2
by: Moon | last post by:
class Vec(list): def __init__(self): list.__init__(self, ) def __iadd__(self, other): assert isinstance(other, Vec) self += other self += other print "right now, v is: ", self, " as you'd...
7
by: samwyse | last post by:
For whatever reason, I need an inproved integer. Sounds easy, let's just subclass int: pass Now let's test it: <class '__main__.test'> 0
0
by: Magnus Schuster | last post by:
Hello, I have written the following small proxy class which I expect to pass all function calls to the 'original' object: --- BEGIN --- class proxy(object): def __init__( self, subject ):...
0
by: Magnus Schuster | last post by:
With this explanation the behaviour is absolutely clear. Can I find some documentation anywhere containing more background information how magic functions are resolved? I haven't been successful...
21
by: Nikolaus Rath | last post by:
Hello, Can someone explain to me the difference between a type and a class? After reading http://www.cafepy.com/article/python_types_and_objects/ it seems to me that classes and types are...
0
by: Christian Heimes | last post by:
AON LAZIO wrote: The form __method__ is reserved for internal methods also known as magic methods. In general you must not name your own methods or attributes __XX__ because the core of Python...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.