蓝绝

博客园 首页 新随笔 联系 订阅 管理

 

 

#

 

 

class Person(object): #Person继承object类
    def __init__(self,name,age):
        self.name=name
        self.age=age
    def info(self):
        print(self.name,self.age)

class Student(Person):
    def __init__(self,name,age,stu_no):
        super().__init__(name,age)
        self.stu_no=stu_no


class Teacher(Person):
    def __init__(self,name,age,teachofyear):
        super().__init__(name,age)
        self.teachofyear=teachofyear


stu=Student('张三',20,'1001')
teacher=Teacher('李四',34,10)

stu.info()
teacher.info()

E:\PycharmProjects\pythonProject\venv\Scripts\python.exe E:/PycharmProjects/pythonProject/demon1/demo44.py
张三 20
1001
----------------------
李四 34
教龄 10


进程已结束,退出代码0

posted on 2022-09-17 19:48  蓝绝  阅读(13)  评论(0编辑  收藏  举报