def__str__(self) : #显示函数重载 'MyTime - string representation' return'%d : %d : %d' % (self.hour, self.min, self.sec) __repr__ = __str__ def__add__(self, time) : #加法重载 'MyTime - overloading the addition operator' h = m = s = 0 t = self.sec + time.sec s = t % 60 m += t /60 t = self.min + time.min + m m = t % 60 h = t / 60 t = self.hour + time.hour + h h = t % 24 return self.__class__(h, m, s)
def__iadd__(self, time) : #自增重载 'MyTime - overloading the in-place addition operator' t = self.sec + time.sec self.sec = t % 60 self.min += t / 60 t = self.min + time.min self.min = t % 60 self.hour += t /60 t = self.hour + time.hour self.hour = t % 24 return self