alternative to raising notimplementederror exceptionespecially if we want to more closely mimic the behavior of python' built-in classesis to raise typeerror here is how we can make fuzzybool __add__(behave just like built-in classes that are faced with an invalid operationdef __add__(selfother)raise typeerror("unsupported operand type(sfor +"'{ }and '{ }'formatself __class__ __name__other __class__ __name__)for unary operationswe want to unimplement in way that mimics the behavior of built-in typesthe code is slightly easierdef __neg__(self)raise typeerror("bad operand type for unary -'{ }'formatself __class__ __name__)for comparison operatorsthere is much simpler idiom for exampleto unimplement ==we would writedef __eq__(selfother)return notimplemented if method implementing comparison operator (=>)returns the built-in notimplemented object and an attempt is made to use the methodpython will first try the reverse comparison by swapping the operands (in case the other object has suitable comparison method since the self object does not)and if that doesn' work python raises typeerror exception with message that explains that the operation is not supported for operands of the types used but for all noncomparison methods that we don' wantwe must raise either notimplementederror or typeerror exception as we did for the __add__(and __neg__(methods shown earlier it would be tedious to unimplement every method we don' want as we have done herealthough it does work and has the virtue of being easy to understand here we will look at more advanced technique for unimplementing methods--it is used in the fuzzyboolalt module--but it is probably best to skip to the next section and return here only if the need arises in practice here is the code for unimplementing the two unary operations we don' wantfor nameoperator in (("__neg__""-")("__index__""index()"))message ("bad operand type for unary { }'{{self}}'format(operator)exec("def { }(self)raise typeerror(\"{ }\format("self=self __class__ __name__))format(namemessage)