class - In an operation between two objects in python whose overloading of the operation as priority? -


For example, if I have __ add __ and __ radd __ Is defined in two classes and I add two objects which will use the definition of operation?

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.

  & 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

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -