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
提交
取消