#装饰器&多继承
#装饰器
def printable1(cls):
cls.print = lambda self:print(self.content)
return cls
@printable1 #Content = printable(Content)
class Content1:
def __init__(self,content):
self.content = content
#验证装饰器实现
c1 = Content1('hello the world1')
c1.print()
##################################################
#多继承
class printable2:
def print(self):
print('```````````')
print('{}'.format(self.content))
class Content2(printable2,Content1):
pass
#验证多继承实现
c2 = Content2('hello the world2')
c2.print()
##################################################
#多继承之后再次增强
class Content3(Content2):
def print(self):
super().print()
print('hello the world3')
#验证多继承增强
c3 = Content3('hello the world2')
c3.print()
运行结果:
hello the world1
```````````
hello the world2
```````````
hello the world2
hello the world3