什么时候用 __repr__ 和 __str__
# 什么时候用__repr__ 和 __str__模拟std库的功能:
>>> import datetime
>>> today = datetime.date.today()
# __str__ 摔交的结果应是可读的:
>>> str(today)
'2017-02-02'
# __repr__的结果应明确如下:
>>> repr(today)
'datetime.date(2017, 2, 2)'
# Python解释器会话使用__repr__检查对象:
>>> today
datetime.date(2017, 2, 2)