Python面向对象程序设计.pptVIP

  • 12
  • 0
  • 约1.17万字
  • 约 40页
  • 2019-12-08 发布于广东
  • 举报
6.1.4 私有成员与公有成员 另外,在IDLE交互模式下,一个下划线“_”表示解释器中最后一次显示的内容或最后一次语句正确执行的输出结果。例如: 3 + 5 8 _ + 2 10 _ * 3 30 _ / 5 6 3 3 1/0 Traceback (most recent call last): File pyshell#2, line 1, in module 1/0 ZeroDivisionError: integer division or modulo by zero _ 3 6.1.4 私有成员与公有成员 class Fruit: def __init__(self): self.__color = Red self.price = 1 apple = Fruit() apple.price #显示对象公开数据成员的值 1 apple.price = 2 #修改对象公开数据成员的值 apple.price 2 print(apple.price, apple._Fruit__color) #显示对象私有数据成员的值 2 Red apple._Fruit__color = Blue #修改对象私有数据成员的值 print(apple.price, apple._

文档评论(0)

1亿VIP精品文档

相关文档