>>> 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)
>>> 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)
发表回复