473,387 Members | 1,464 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,387 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 5649
__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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.