Program - class to show implementation of equality and less than implementation in an class


Topic: Program - class to show implementation of equality and less than implementation in an class

Solution

class GqLt:
    def __init__(self, msg="Demo of lt and eq in class"):
        self.msg = msg
    def __eq__(self, other):
        """
        Equality check between two object of same class.
        It is mandatory to implement __eq__ in class to do equality check.
        """
        if isinstance(other, GqLt):
            return "Code to be written here to match equality check between two object of same class"
        else:
            raise ValueError('Invalid comparison')
    def __lt__(self, other):
        """
        Less than or greater than check between two objects of same class.
        It is mandatory to implement __eq__ in class to do equality check.
        """
        if isinstance(other, GqLt):
            return "Code to be written here to match equality check between two object of same class"
        else:
            raise ValueError('Invalid comparison')



List all Python Programs