classes and object-oriented programming creates string that' intended for nice output formatting (this is the string that would be produced by the print statementthe other operatorssuch as _add_ (and _sub_ ()implement mathematical operations delicate matter with these operators concerns the order of operands and type coercion as implemented in the previous examplethe _add_ (and _sub_ (operators are applied only if complex number appears on the left side of the operator they do not work if they appear on the right side of the operator and the left-most operand is not complex for examplec complex( , complex( , traceback (most recent call last)file ""line in typeerrorunsupported operand type(sfor +'intand 'complexthe operation works partly by accident all of python' built-in numbers already have real and imag attributesso they were used in the calculation if the other object did not have these attributesthe implementation would break if you want your implementation of complex to work with objects missing these attributesyou have to add extra conversion code to extract the needed information (which might depend on the type of the other objectthe operation does not work at all because the built-in floating point type doesn' know anything about the complex class to fix thisyou can add reversedoperand methods to complexclass complex(object)def _radd_ (self,other)return complex(other real self realother imag self imagdef _rsub_ (self,other)return complex(other real self realother imag self imgthese methods serve as fallback if the operation failspython tries to execute _radd_ ( first before issuing typeerror older versions of python have tried various approaches to coerce types in mixedtype operations for exampleyou might encounter legacy python classes that implement _coerce_ (method this is no longer used by python or python alsodon' be fooled by special methods such as _int_ () _float_ ()or _complex_ (although these methods are called by explicit conversions such as int(xor float( )they are never called implicitly to perform type conversion in mixed-type arithmetic soif you are writing classes where operators must work with mixed typesyou have to explicitly handle the type conversion in the implementation of each operator types and class membership tests when you create an instance of classthe type of that instance is the class itself to test for membership in classuse the built-in function isinstance(obj,cnamethis lib fl ff