class SchoolMember(object):
member=0
def __init__(self,name,age,sex):
self.name=name
self.age=age
self.sex=sex
self.enroll()
def enroll(self):
SchoolMember.member+=1
print("-----The[%s]SchoolMember[%s] is enrolled!"%(self.member,self.name))
def tell(self):
print("hello my name is [%s]"%self.name)
class Teacher(SchoolMember):
def __init__(self,name,age,sex,course,salary):
super(Teacher,self).__init__(name,age,sex)
#SchoolMember.__init__(self,name,age,sex)
self.course=course
self.salary=salary
def teaching(self):
print("Teacher[%s]can teaching [%s]"%(self.name,self.course))
class Student(SchoolMember):
def __init__(self,name,age,sex,course,tuition):
super(Student,self).__init__(name,age,sex)
self.course=course
self.tuition=tuition
def pay_tuition(self):
print("student[%s]paying tuition[%s]"%(self.name,self.tuition))
t1=Teacher("zy",23,'F',"PY",1000)
t2=Teacher("zlj",20,'F',"PY",10000)
s1=Student("sb",24,"Female","python",15000)
s1=Student("someone",21,"Female","python",15000)
t1.tell()
s1.tell()
t1.teaching()
s1.pay_tuition()
输出---------------------------------------------------
D:Pythonpython.exe D:/Python/编辑器/代码/shool.py
-----The[1]SchoolMember[zy] is enrolled!
-----The[2]SchoolMember[zlj] is enrolled!
-----The[3]SchoolMember[sb] is enrolled!
-----The[4]SchoolMember[someone] is enrolled!
hello my name is [zy]
hello my name is [someone]
Teacher[zy]can teaching [PY]
student[someone]paying tuition[15000]