class SchoolMember:
'''Represents any school member'''
def __init__(self, name, age):
self.name = name
self.age = age
def tell(self):
print '( name:', self.name, ' age:', self.age ,' )'
class Student(SchoolMember):
def __init__(self, name, age, score):
SchoolMember.__init__(self, name, age)
self.score = score
def tell(self):
print '( name:', self.name,' age:', self.age,' score:',self.score,' )'
class Teacher(SchoolMember):
def __init__(self, name, age, course):
SchoolMember.__init__(self, name, age)
self.course = course
def tell(self):
print '( name:', self.name, ' age:', self.age, ' course:', self.course, ' )'
s1 = Student('tb', '20', 32)
s1.tell()
t1 = Teacher('sb', '32', 'Program design')
t1.tell()
Python中的类和继承
最新推荐文章于 2022-08-09 14:36:45 发布