加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python 类(2)

发布时间:2020-12-20 12:51:07 所属栏目:Python 来源:网络整理
导读:""""""class BaseCat(object): """ 猫科基础类""" tag = ‘猫科动物‘ def __init__(self,name): self.name = name def eat(self): print(‘吃东西‘)class Tiger(BaseCat): """ 老虎类 """ def eat(self): # 调用父类方法 super(Tiger,self).eat() print(‘
""""""class BaseCat(object):    """ 猫科基础类"""    tag = ‘猫科动物‘    def __init__(self,name):        self.name = name    def eat(self):        print(‘吃东西‘)class  Tiger(BaseCat):    """    老虎类    """    def eat(self):        # 调用父类方法        super(Tiger,self).eat()        print(‘还喜欢吃肉‘)class Panda(BaseCat):    """    熊猫类    """class PetCat(BaseCat):    """    家猫类    """    def eat(self):        # 调用父类方法        super(PetCat,self).eat()        print(‘还喜欢吃猫粮‘)class HuaCat(PetCat):    """    中华田园猫    """    def eat(self):        # 调用父类方法        super(HuaCat,self).eat()        print(‘还喜欢吃零食‘)class DuanCat(PetCat):    """    英国短毛    """    # def eat(self):    #     super(DuanCat,self).eat()    #     print(‘我啥都吃‘)if __name__ == ‘__main__‘:    # 实例化 中华田园猫    Cat = HuaCat(‘小黄‘)    Cat.eat()    print(‘--------------------‘)    # 实例化 英国短毛    Cat_d = DuanCat(‘小辉‘)    Cat_d.eat()    # 子类判断  True    print(issubclass(DuanCat,BaseCat))

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读