+ 1
[DONE] Why it returns a non-string ?
--- CORRECTED --- class Queue: def __init__(self, contents): self._hiddenlist = list(contents) def __repr__(self): return str(self._hiddenlist) --- WRONG --- # TypeError. Why __str__ return non-string # Error class Queue: def __init__(self, contents): # self._hiddenlist = list(contents) self._hiddenlist = contents def __repr__(self): return print(self._hiddenlist) queue = Queue([1, 2, 3]) print(queue)
2 Answers
+ 4
replace
return print(...
with
return str(...
__repr__ should return string to be printed.
print() returns something on "screen", or None object.
0
@yuri great thx!!!! Pls advice, where i must find replies on similar questions?