鱼C论坛

 找回密码
 立即注册
查看: 586|回复: 1

[已解决]倒数第五行的 temp 算是类属性还是实例属性 怎么访问

[复制链接]
发表于 2018-8-12 14:17:21 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. <div class="blockcode"><blockquote>import time as t

  2. class MyTimer():
  3.     def __init__(self):
  4.         self.lasted=[]
  5.         self.starttime=0
  6.         self.endtime=0
  7.         self.mpt = "please start"
  8.         self.unit = ["年","月","天","小时","分","秒"]
  9.         
  10.         
  11.     def __str__(self):
  12.         return self.mpt
  13.         
  14.     __repr__=__str__

  15.     def start(self):
  16.         self.starttime=t.localtime()
  17.         print("开始计时")

  18.     def end(self):
  19.         if not self.starttime:
  20.             print("请先调用starttime")
  21.         else:
  22.             self.endtime=t.localtime()
  23.             self.cal()
  24.             print("结束计时")

  25.     def cal(self):
  26.         self.mpt=""
  27.         for i in range(6):
  28.             temp = self.endtime[i]-self.starttime[i]
  29.             self.lasted.append(temp)
  30.             if self.lasted[i]:
  31.                 self.mpt+=str(self.lasted[i])+str(self.unit[i])
  32.         return self.mpt
  33.         
复制代码





最佳答案
2018-8-12 14:33:37
啥都不是,函数里的临时变量
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-8-12 14:33:37 | 显示全部楼层    本楼为最佳答案   
啥都不是,函数里的临时变量
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-3-29 14:52

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表