#
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