2008-07-15: Selected articles now have experimental "comment" links in the left column and at the bottom. You're welcome to use them for commenting and voting on articles. For a bit more on this, see this page. /F

The __add__ method

__add__(self, other)

These methods are called to implement the binary arithmetic operations (+, -, \*, //, %, divmod(), pow(), \*\*, <``<, ` >`>, &, ^, |). For instance, to evaluate the expression x+y, where x is an instance of a class that has an __add__ method, x.\_\_add\_\_(y) is called. The __divmod__ method should be the equivalent to using __floordiv__ and __mod__; it should not be related to __truediv__ (described below). Note that __pow__ should be defined to accept an optional third argument if the ternary version of the built-in pow function is to be supported.

 

Comment:

"These methods are called to implement the binary arithmetic operations..." It seems to me, this description should apply to all __something__ methods, not just __add__ (note "These").

OffTopic: I would love to contribute. How can I do it? Will you implement wiki someday?

Posted by Alexey Shamrin (2006-12-08)

Comment:

"I would love to contribute. How can I do it?" For now, just keep reviewing things! I doubt we'll turn this into a public wiki, but some kind of "edit through the web" support for trusted users is definitely on the drawing board.

Posted by Fredrik (2007-01-04)

A Django site. this page was rendered by a django application in 0.03s 2008-07-25 10:14:32.236073. hosted by webfaction.