python-super函数

来源:互联网 发布:java初学者书籍推荐 编辑:程序博客网 时间:2024/06/05 09:22

super函数主要为了调用超类的方法

__metaclass__=typeclass Bird():    def __init__(self):        self.hungry=True    def eat(self):        if self.hungry:            print 'Ahah'            self.hungry=False        else:            print 'No,thanks'class SongBird(Bird):    def __init__(self):        super(Bird,self).__init__()        self.sound='Squark'    def sing(self):        print self.sound

—>a=SongBird()
—>a.sing()
Squawk!

0 0
原创粉丝点击