在stop方法中调用了self._calc(),这样的写法对吗,在_calc(self)方法中,对方法内的代码不理解,请讲解一下代码的执行过程以及参数的传递
>>> import time as t
>>> class Mytimer:
def start(self):
self.start = t.localtime()
print("计时开始......")
def stop(self):
self.stop = t.localtime()
self._calc()
print("计时结束!")
def _calc(self):
self.lasted = []
self.prompt = "总共运行了"
for index in range(6):
self.lasted.append(self.stop[index] - self.start[index])
self.prompt += str(self.lasted[index])
print(self.prompt)
>>> t1 = Mytimer()
>>> t1.start()
计时开始......
>>> t1.stop()
总共运行了000006
计时结束!
>>>