class - In an operation between two objects in python whose overloading of the operation as priority? -
For example, if I have If left and right hand objects are unrelated, then the left hand wins the object. However, if an object is a subcategory of another object, then the subcategory wins it despite the left or right hand object. __ add __ and
__ radd __ Is defined in two classes and I add two objects which will use the definition of operation?
& gt; & Gt; & Gt; Square Fu (object): ... def __add __ (self, rhs): ... print ('foo.add') ... def __radd __ (self, rhs): ... print ('foo.radd ') ... & gt; & Gt; & Gt; Square Bar (Foo): ... def __add __ (auto, rhs): ... print ('bar.add') ... def __radd __ (auto, rhs): ... print ('bar.radd ') ... & gt; & Gt; & Gt; A = fu ()> gt; & Gt; & Gt; B = bar ()> gt; & Gt; & Gt; A + b bar.radd & gt; & Gt; & Gt; B + once.ad & gt; & Gt; & Gt;
Comments
Post a Comment