调用对象的 __repr__
方法,获得该方法的返回值,如下例子返回值为字符串
>>> class Student(): def __init__(self,id,name): self.id = id self.name = name def __repr__(self): return 'id = '+self.id +', name = '+self.name
调用:
>>> xiaoming = Student(id='1',name='xiaoming') >>> xiaoming id = 1, name = xiaoming >>> ascii(xiaoming) 'id = 1, name = xiaoming'