The expression x + y is translated into x.__add__(y).
However, if x hasn't implemented __add__, and x and y are of different types, then y.__radd__(x) is called.
There are equivalent r methods for all magic methods just mentioned. Example:
def __init__(self, cont):
self.cont = cont
spam = SpecialString("spam")
hello = SpecialString("Hello world!") print(spam / hello)Try It Yourself Result:>>>
In the example above, we defined the division operation for our class SpecialString.
If you want to change selection, open original toplevel document below and click on "Move attachment"
last reprioritisation on
suggested re-reading day
started reading on
finished reading on
Do you want to join discussion? Click here to log in or create user.