We have two objects in Python class TwoNum consisting of two values x and y. And then compare the two objects using a greater than operator which compares the addition of the values.
Class and its members used in the program
- Class : TwoNum
- Method : getValues() - get users input for the values of the class.
- Method : putValues() - prints values of the class.
- Method : __add__() [addition operator] - adds the values of two objects of the class.
- Method : __gt__() [greater than operator] - compares the values of objects of the class and returns the true if first is greater than second.
- Variable : x - stores an integer value.
- Variable : y - stores an integer value
Program to illustrate comparison operator
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer