Skip to content

Latest commit

 

History

History
28 lines (24 loc) · 611 Bytes

34.md

File metadata and controls

28 lines (24 loc) · 611 Bytes
@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'
[上一个例子](33.md) [下一个例子](35.md)