组合
多个数据属性通过一个类实例化的对象做关联
# -*- coding:utf8 -*-
class Forest: #定义总类结合-森林
def __init__(self,other): #定义类的属性
self.other = other #总类中的类别
self.addr = Animal() #把其它类别结合到总类中
self.type = Plant()
class Animal: #定义的动物类
def _animal(self): #定义的动物属性
print("这是动物类别")
class Plant: #定义的植物类
def _plant(self): #定义的植物属性
print("这是植物类别")
P = Forest("测试") #总类实例化
print(P.other) #总类自定义类输出
P.addr._animal() #总类结合的其它类输出
# -*- codin