Python_15
来源:互联网 发布:昆明行知中学招聘 编辑:程序博客网 时间:2024/05/17 05:07
- 1.
__metaclass__=type#使用新类,否则super方法会出错class bird: def __init__(self): self.hungry=True def eat(self): if self.hungry: print 'Aaaah...' else: print 'No, thanks!'class songBird(bird): def __init__(self): super(songBird,self).__init__() self.sound='Squark!' def sing(self): print self.sound
构造方法init。
>>> sb=songBird()>>> sb.eat()Aaaah...>>> sb.sing()Squark!