Answers for "difference between __str__ and __repr__"

2

__repr__ or __str__

very briefly
 - The default implementation is useless (it’s hard to think of one which wouldn’t be, but yeah)
 - __repr__ goal is to be unambiguous
 - __str__ goal is to be readable
 - Container’s __str__ uses contained objects’ __repr__
 
see source for more info
Posted by: Guest on October-14-2020
0

difference between __str__ and __repr__

>>> import datetime
>>> now = datetime.datetime.now()
>>> now.__str__()
'2020-12-27 22:28:00.324317'
>>> now.__repr__()
'datetime.datetime(2020, 12, 27, 22, 28, 0, 324317)'
Posted by: Guest on May-23-2021

Code answers related to "difference between __str__ and __repr__"

Python Answers by Framework

Browse Popular Code Answers by Language