34
编辑日期: 2024-11-28 文章阅读: 次
@author jackzhenguo
@desc
@date 2019/3/10
34 ascii 展示对象
调用对象的 __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'