|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
self.last[index],这是什么意思
还有 for index in range(6)
包括self.stop self.stat 后面都加了一个[index]
这里的index是干嘛用的
import time as t
class Mytime():
#开始计时
def start(self):
self.start = t.localtime()
print('开始计时')
#计时结束
def stop(self):
self.stop = t.localtime()
print('计时结束')
self.cloc()
#内部方法,计算运行时间
def cloc(self):
self.last = []
self.print = "一共用了"
for index in range(6):
self.last.append(self.stop[index] - self.start[index])
self.print +=str(self.last[index])
print(self.print)
一般有这个方括号表示这个变量,比如你的self.stop self.stat,都是一个可以索引的变量,比如列表,字典,元组。
self.stat[1]就是代表我要访问self.stat里面的下标为1的数据
self.stat[index]就是我要访问下标为index的数据
所以index一定是一个整型变量
|
|