关于repr的问题
class Person(object):
def __init__(self, name, gender):
self.name = name
self.gender = gender
class Student(Person):
def __init__(self, name, gender, score):
super(Student, self).__init__(name, gender)
self.score = score
def __tr__(self): //注意此处的str变成了tr
return '(Student: %s, %s, %s)' % (self.name, self.gender, self.score)
__repr__ = __tr__ //若这句存在则能正常输出,若这句不存在则输出错误,为什么呢?
s = Student('Bob', 'male', 88)
print s