class OldboyPeople:
"""由于学生和老师都是人,因此人都有姓名、年龄、性别"""
school = 'oldboy'
def __init__(self, name, age, gender):
self.name = name
self.age = age
self.gender = gender
class OldboyStudent(OldboyPeople):
def choose_course(self):
print('%s is choosing course' % self.name)
class OldboyTeacher(OldboyPeople):
def score(self, stu_obj, num):
print('%s is scoring' % self.name)
stu_obj.score = num
stu1 = OldboyStudent('tank', 18, 'male')
tea1 = OldboyTeacher('nick', 18, 'male')
tea1.score(stu1, 99)
比如这段代码里面,为什么tea1用自己的score方法,第一个参数必须要是stu1对象,还有stu_obj.score = num 这句没看懂,自己的参数调用自己?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…