python类 组合


#实现代码复用
#!/usr/bin/env python # -*- coding: utf-8 -*- # author:albert time:2019/4/19 0019 import copy class MobilePhone: def __init__(self,cpu,screen): self.cpu = cpu self.screen = screen class Cpu: def calculation(self): print('cpu',self) class Screen: def show(self): print('screen',self) m1 = MobilePhone(Cpu(),Screen()) m1.cpu.calculation() m1.screen.show()

 

posted @ 2019-04-19 21:20  文二1234  阅读(304)  评论(0编辑  收藏  举报