class Animal :
def say():
print("haha")
pass
def run(self , dist , how):
how(dist , self.name)
pass
pass
class Dog(Animal):
def __init__(self) -> None:
self.name = '旺财'
def say(self):
print("hau")
class Cat(Animal):
def __init__(self) -> None:
self.name = '小黄'
def say(self):
print("meow")
pet = Dog()
# pet.say() # prints "hau"
another_pet = Cat()
# another_pet.say() # prints "meow"
def running(dist , name):
print(f"{name}跑了{dist}米距离。")
pass
pet.run(10 , running)
another_pet.run(20 , running)
# my_pets = [pet, another_pet]
# for a_pet in my_pets:
# a_pet.say()
跟亮哥学oop
最新推荐文章于 2024-06-26 15:32:33 发布