import time as t
class timer:
def __init__(self):
print('这是一个计时器')
self.unitlist=['年','月','日','时','分','秒']
def __str__(self):
return self.thepast
__repr__=__str__
def start(self):
self.begin=t.localtime()
self.thepast=[]
self.numlist=[]
def stop(self):
self.end=t.localtime()
for i in range(6):
self.numlist.append(str(self.end[i]-self.begin[i]))
self.numlist.append(self.unitlist[i])
self.thepast='经过了'+(''.join(str(self.numlist)))
"".join(列表)
# 不是字符串
''.join(self.numlist)