python提示SongBird instance has no attribute 'sound'
高洛峰
高洛峰 2016-10-28 10:14:31
0
1
796

提示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,这是书上的代码。检查过很多遍,就是通不过。

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

全員に返信(1)
三叔
_metaclass_ = type
class Bird(object):
    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( )

__init__不是_init_

いいねを押す +0
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!