python中类的继承

class Animal():

    def __init__(self, name, age):
        self.name = name
        self.age = age

    def eat(self):
        return "我在吃东西"

    def sleep(self):
        print("animal {} is sleep".format(self.name))
        return "我在睡觉觉"

    def __repr__(self):
        return "my name:{},age:{}".format(self.name,self.age)



animal=Animal("小狗",7)

print(animal)


class Bird(Animal):
    def fly(self):
        return "我能飞起来"

bird=Bird("黄鹂","8岁")
print(bird.fly())


class Parrot(Bird):
    def speak(self):
        return "我能唱歌,也能说话"

  

posted @ 2021-08-04 14:37  年轻人——001  阅读(24)  评论(0编辑  收藏  举报