repr python class code example
Example 1: __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
Example 2: repr() in python
#The repr() function returns a printable representation of the given object.
#repr() takes a single object.
#Syntax
val = "string"
print(repr(val)) #output ---->"'string'"