类的组合的主要作用是封装前一个类的作用,其他的和函数的套用差不多!我是按照我的例子来理解的!!!
class Wear:
def __init__(self,hat,clothes,trousers,shos):
self.hat=hat
self.clothes=clothes
self.trousers=trousers
self.shos=shos
def wear(self):
return ("喜欢 白%s帽子 黑%s衣服 红%s裤子 蓝%s鞋子"%(self.hat,self.clothes,self.trousers,self.shos))
class person:
def __init__(self,name):
self.name=name
def show(self,hat,clothes,trousers,shos):
s1=Wear(hat,clothes,trousers,shos)#我不知道你的类(或是你的函数是怎么样的,我就只知道我在我的类里面调用你的方法来解决我的问题!)
print(self.name,s1.wear())
a=person('小明')
a.show('平底锅','T恤','牛仔裤','绣花鞋')原文:http://blog.51cto.com/853056088/2133803