开发者社区> 问答> 正文

python父类继承?报错

源码如下.class Animal:
    def __init__(self):
        self.hungry=True
    def eat(self):
        print 'Animal is eating food'
class Dog(Animal):
    def __init__(self):
        #Animal.__init__(self)
        super(Dog, self).__init__()
        print 'this is a dog'
    def eat(self):
        print 'Dog is eating bones'
dog=Dog()
print 'is it hungry? ',dog.hungry

报错:

    super(Dog, self).__init__()
TypeError: must be type, not classobj

 

求解决!

展开
收起
爱吃鱼的程序员 2020-06-22 11:34:37 283 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB
    第一行classAnimal(object):

    解决了这个是必须指定出来超类么?

     

    用super得这样

    多谢

    2020-06-22 11:34:54
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载