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 "我能唱歌,也能说话"
全世界的程序员们联合起来吧!