要求:python3
描述:创建一个基类(父类):Animal、子类:Bird,使用super()实现子类调用父类的方法。
#coding=utf8 __author__ = "Marlon" #既要执行父类的实例化方法,又要执行子类的实例化方法 class Animal: def __init__(self, name, sex, age): self.name = name self.sex = sex self.age = age def eat(self, a1): print('%s吃%s' % (self.name, a1)) def drink(self): print('%s喝东西' % (self.name)) class Brid(Animal): def __init__(self, name, sex, age, wing): # self b1对象 name '鹦鹉',sex '公',age 20, wing '绿翅膀' ''' self=b1对象 name='鹦鹉' sex='公' age= 20, wing='绿翅膀' ''' super().__init__(name, sex, age) # super(Brid,self).__init__(name,sex,age) self.wing = wing def bark(self): print('嗷嗷叫') def eat(self, argv): super().eat(argv) print('鸟吃虫子...') b1 = Brid('鹦鹉', '公', 20, '绿翅膀') # print(b1.__dict__) b1.eat('零食')