标签:sel The on() teacher 学费 print 重写 object 作者
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# 作者:Presley
# 邮箱:1209989516@qq.com
# 时间:2018-08-05
# OOP学习2
class SchoolMember(object):
member_numbers = 0
def __init__(self,name,age,sex):
self.name = name
self.age = age
self.sex = sex
self.enroll() #注册
def enroll(self):
SchoolMember.member_numbers += 1
print("The [{0}] school member [{1}] is enrolled!".format(self.member_numbers,self.name))
def tell(self):
print("Hello my name is %s"%(self.name))
class Teacher(SchoolMember):
def __init__(self,name,age,sex,course,salary): #course 课程 ,salary 薪水
super(Teacher,self).__init__(name,age,sex)#先定义重写父类的name,age,sex这三个值,然后把父类的name,age,sex的值拿过来
self.course = course
self.salary = salary
#SchoolMember.__init__(self,name,age,sex)与super方法一样
def teaching(self):
print("Teacher [{0}] is teaching [1]".format(self.name,self.course))
class Student(SchoolMember):
def __init__(self,name,age,sex,course,tuition): #tuition学费
super(Student,self).__init__(name,age,sex)
self.course = course
self.tuition = tuition
def pay_tution(self): #交学费
print("cao,student [{0}] paying tution [{1}]".format(self.name,self.tuition))
t1 = Teacher("Alex",22,‘F‘,"PY",1000)
t2 = Teacher("Tenglan",25,"N/A","PY",900)
s1 = Student("SanJiang",24,"Female","python",15000)
s2 = Student("BaoAn",23,"F","python",5000)
t1.tell()
t1.teaching()
s1.pay_tution()
标签:sel The on() teacher 学费 print 重写 object 作者
原文地址:https://www.cnblogs.com/Presley-lpc/p/9690790.html