Python_练习_24.3.22

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

    def describe(self):
        print(f"我的名字是{self.name},我的年龄是{self.age}")


class Student(School_number):
    def __init__(self, name, age, sex):
        School_number.__init__(self, name, age)
        self.sex = sex

    def describe(self):
        super().describe()
        print(f"我的名字是{self.name},我的年龄是{self.age},性别是{self.sex}")


student = Student("张三", 18, "男")
student.describe()
class Person():
    def say_hello(self):
        print("打招呼")


class Chinese(Person):
    def say_hello(self):
        super().say_hello()
        print("你好")


chinese = Chinese()
chinese.say_hello()
class Animal():
    def speak(self):
        pass


class Dog(Animal):
    def speak(self):
        print("小狗汪汪叫")


class Cat(Animal):
    def speak(self):
        print("小猫喵喵叫")


class Chicken(Animal):
    def speak(self):
        print("小鸡唧唧叫")


# dog = Dog()
# dog.speak()
# cat = Cat()
# cat.speak()
def animal_speak(animal):
    animal.speak()


dog = Dog()
animal_speak(dog)
cat = Cat()
animal_speak(cat)
温馨提示:本文最后更新于2024-03-22 15:26:30,某些文章具有时效性,若有错误或已失效,请在下方留言或联系站长
© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享
相关推荐
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情

    暂无评论内容