class Time(object): def __init__(self, hour, min): self.hour = hour self.min = min def __str__(self): """overloading the str operator (STRing)""" return "[ {:2}:{:2} ]".format(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 class TimeUK(Time): """Derived (or inherited class)""" def __str__(self): """overloading the str operator (STRing)""" if self.hour < 12: ampm = "am" else: ampm = "pm" return "[{:2}:{:2}{}]".format(self.hour % 12, self.min, ampm) if __name__ == "__main__": t3 = TimeUK(15, 45) print("TimeUK object = %s" % t3) t4 = TimeUK(16, 00) print("compare t3 and t4: ") if t3 > t4: print("t3 is greater than t4") else: print("t3 is not greater than t4")