class Animal: def __init__(self, animal): self.animal = animal def type(self, type=self.animal):
print type
2 回答

温温酱
TA贡献1752条经验 获得超4个赞
如果打印的默认值非要设为self.animal的话,试试这样:
class Animal(object): def __init__(self,animal): self.animal = animal def type(self,type=None): print type if type else self.animal
你还需要了解一下self,在类中哪里可以访问得到self,哪里不可以!
添加回答
举报
0/150
提交
取消