class Student(object):
def __init__(self, name, gender, score):
self.name = name
self.gender = gender
self.score = score
def __str__(self):
return 'name is {}, gender is {}, score is {}'.format(self.name, self.gender, self.score)
def __repr__(self):
return 'name is {}, gender is {}, score is {}'.format(self.name, self.gender, self.score)
s = ('xiaoming','Male',90)
print(s)
?因为你是直接给s赋值,并没有调用Student函数啊
倒数第二句的问题吧。s=Student('xiaoming','Male'90) 最后的打印,显示给用户的打印方式: print(str(s)) ,显示给开发人员的就用 print(s) 打印就好。