提示SongBird instance has no attribute 'sound'
_metaclass_ = type
class Bird:
def _init_(self):
self.hungry = True
def eat(self):
if self.hungry:
print 'Aaaaa.....'
self.hungry = False
else:
print 'No, think'
class SongBird(Bird):
def _init_(self):
super(SongBird, self)._init_()
self.sound = 'Squawk!'
def sing(self):
print self.sound
sb = SongBird( )
sb.sing( )
刚开始学python,这是书上的代码。检查过很多遍,就是通不过。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
__init__不是_init_