class Animal:
def eat(self):
print("%s 吃 " % self.name)
def drink(self):
print("%s 喝 " % self.name
class Cat(Animal):
breed = '猫'
def __init__(self, name):
self.name = name
def cry(self):
print('喵喵叫')
def displaybreed(self):
print('%s它是一只%s' % (self.name,Cat.breed))
=
c1 = Cat('贝贝')
print(c1.breed)
c1.displaybreed()
c1.breed='老虎'
print(c1.breed)
c1.displaybreed()
c1.eat()
-------------------------------------------------------------------------------------------打印出的结果:
猫
贝贝它是一只猫
老虎
贝贝它是一只猫
贝贝 吃
请问要怎么才能使最后一次c1.displaybreed() 显示贝贝它是一只老虎 ?
c1.eat()
def eat(self):
print("%s 吃 " % self.name)
def drink(self):
print("%s 喝 " % self.name
class Cat(Animal):
breed = '猫'
def __init__(self, name):
self.name = name
def cry(self):
print('喵喵叫')
def displaybreed(self):
print('%s它是一只%s' % (self.name,Cat.breed))
=
c1 = Cat('贝贝')
print(c1.breed)
c1.displaybreed()
c1.breed='老虎'
print(c1.breed)
c1.displaybreed()
c1.eat()
-------------------------------------------------------------------------------------------打印出的结果:
猫
贝贝它是一只猫
老虎
贝贝它是一只猫
贝贝 吃
请问要怎么才能使最后一次c1.displaybreed() 显示贝贝它是一只老虎 ?
c1.eat()