Jan-15-2020, 12:48 PM
(Jan-14-2020, 11:25 PM)stullis Wrote: print() calls obj.__repr__() whereas str() calls obj.__str__().A correction here,print() call
__str__()
the same do str().So in my code before in Thread.
>>> # Call __str__ >>> print(sword) The item is: sword >>> str(sword) 'The item is: sword' >>> # Call __repr__ >>> sword Items('sword') >>> repr(sword) "Items('sword')"
__str__
method should primarily be human readable.__repr__
goal is to be unambiguous,and should be as explicit as possible about what this object is.The resulting string is intended more as help for developers and debugging.