Python程序的设计_清华大学出版社_董付国第6章_面向对象程序的设计说明.pptVIP

  • 2
  • 0
  • 约8.53千字
  • 约 31页
  • 2019-11-03 发布于安徽
  • 举报

Python程序的设计_清华大学出版社_董付国第6章_面向对象程序的设计说明.ppt

6.3.1 Python2.x中的属性 class Test: def show(self): print self.value print self.__v t = Test() t.show() 出错信息 AttributeError: Test instance has no attribute value t.value = 3 t.show() 3 出错信息 AttributeError: Test instance has no attribute _Test__v t.__v = 5 t.show() 3 出错信息 AttributeError: Test instance has no attribute _Test__v t._Test__v = 5 t.show() 3 5 6.3.2 Python3.x中的属性 class Test: def __init__(self, value): self.__value = value @property def value(self): return self.__value t = Test(3) t.value 3 t.value = 5 出错信息 AttributeError: cant set attribute t.v=5 t.v 5 del t.v

文档评论(0)

1亿VIP精品文档

相关文档