class Person: school = 'oldboy' def __init__(self,name,age): self.name = name self.age = age class Student(Person): def __init__(self,name,age,course): Person.__init__(self,name,age) self.course = course class Teather(Person): def __init__(self,name,age,level): Person.__init__(self,name,age) self.level = level stu1 = Student('xichem',18,'python') t1 = Teather('nick',30,10) print(stu1.school) print(stu1.__dict__) print(t1.__dict__)
oldboy
{'name': 'xichem', 'age': 18, 'course': 'python'}
{'name': 'nick', 'age': 30, 'level': 10}python