So I have this class with the repr method implemented
import reprlib
class Test:
def __init__(self, aList):
self.my_list = [c for c in aList]
def __repr__(self):
# return " ".join((str(i) for i in self.my_list))
# return reprlib.repr(self.my_list)
# return repr(self.my_list) # builtin repr method
return str(self.my_list)
What are the differences between the various implementations of the repr method?
They all have the same output.
Code used on all implementations:
x = [2, 5, 11]
t = Test(x)
print(t) # >> [2, 5, 11]
t # >> output [2, 5, 11]
Edit: The first implementation (join method) will produce the items without brackets. Disregard that if you like. My focus is what are differences among the last three and which is the better implementation among all four implementation.
Edit: This is clearly not about the differences between the repr and str methods. It's about which implementation should I consistently adopt when implementing the repr method (or the str method for that matter).