class Time(object): def __init__(self, hour, min): self.hour, self.min = hour, min def __str__(self): """overloading the str operator (STRing)""" return "[ %2d:%2d ]" % (self.hour, self.min) def __repr__(self): """overloading the repr operator (REPResentation)""" return "Time(%2d, %2d)" % (self.hour, self.min) def __gt__(self, other): """overloading the GreaTer operator""" selfminutes = self.hour * 60 + self.min otherminutes = other.hour * 60 + other.min if selfminutes > otherminutes: return True else: return False if __name__ == "__main__": t1 = Time(15, 45) t2 = Time(10, 55) print("String representation of the object t1: %s" % t1) print("Representation of object = %r" % t1) print("compare t1 and t2: "), if t1 > t2: print("t1 is greater than t2")