python repr
# The repr() function returns a printable representational string of the given object.
>>> var = 'foo'
>>> print(repr(var))
"'foo'"
__ Repre _ _ nebo _ _ 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
__ repr _ _ v Pythonu
def __repr__(self) -> str:
return
python__ repr _ _ význam
>>>x=4
>>>repr(x)
'4'
>>>str(x)
'4'
>>>y='stringy'
>>>repr(y)
"'stringy'"
>>>str(y)
'stringy'
krajta _ _ 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)'