repr_str方法
该方法可以改变字符串的显示格式
1 class School: 2 3 def __init__(self,name,addr,type): 4 self.name = name 5 self.addr = addr 6 self.type = type 7 8 #改变字符串的显示格式 9 def __repr__(self): 10 return 'School(%s,%s)' % (self.name,self.addr) 11 12 def __str__(self): 13 return '(%s,%s)' % (self.name,self.addr) 14 15 16 s1 = School('小猿圈','北京','私立') 17 print('from repr:',repr(s1)) 18 print('from str:',str(s1)) 19 print(s1)