Question: The method _ _ cmp _ _ ( self , other ) is implicitly invoked by the relational operators such as < , < =

The method __cmp__(self, other) is implicitly invoked by the relational operators such as <,<=,>=,>,==,!= and <>. Create the class Box as described in the previous question. What error message is produced when you compare two instances of this class? Now define the method __cmp__ so that it returns -1 if the value held in the box is less than the value held in the box referenced by the parameter other, is 0 if they are equal, and 1 if the value is greater than the value of other. Test each of the relational operators to see that they now work.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!