__metaclass__=type
class Bird:
def __init__(self):
self.hungry = True
def eat(self):
if self.hungry:
print 'Aaaah...'
self.hungry = False
else:
print "No,thanks!"
class SongBird(Bird):
def __init__(self):
#Bird.__init__(self)
super(SongBird, self).__init__()
self.sound = 'Squawk'
def sing(self):
print self.sound
songbird = SongBird()
songbird.sing()
songbird.eat()
songbird.eat()
print "**********Done!Tada!!**********"
上面这段代码核心是:如何继承super类~重点是:
__metaclass__=type
<pre name="code" class="python">super(SongBird, self).__init__()