- # 封装:
- # 1. 对属性的封装
- # 2. 对功能的封装
- # 3. 模块
- # 4. 包
- class Student:
- def __init__(self, num, name, clazz):
- self.num = num
- self.name = name
- self.clazz = clazz
- #
- #
- stu = Student("10010", "曹宝宝", "三年二班") # 把多个信息 (值) 保存在一个对象里面
- stu2 = Student("10086", "王迪", "三年一班")
- def kill_stu(s):
- print("杀 %s" % (s.name))
- kill_stu(stu2)
- class Game:
- def login(self):
- print("登录")
- def recharge(self):
- print("充钱")
- def uninstall(self):
- print("卸载")
- def zhaoduixiang(self):
- print("找对象")
- #
- #
- #
- #
- #
- class Game1:
- def recharge(self):
- print("充钱")
- def uninstall(self):
- print("卸载")
- #
- #
- class Game2:
- def recharge(self):
- print("充钱")
- def uninstall(self):
- print("卸载")
- g = Game2()
- g.uninstall()
来源: http://www.bubuko.com/infodetail-2888230.html