+ 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)

18th Nov 2017, 8:03 PM
Vitalij Bredun ♡ Python Petersburg
Vitalij Bredun ♡ Python Petersburg - avatar
2 Réponses
+ 4
replace return print(... with return str(... __repr__ should return string to be printed. print() returns something on "screen", or None object.
18th Nov 2017, 8:40 PM
yuri
0
@yuri great thx!!!! Pls advice, where i must find replies on similar questions?
18th Nov 2017, 9:36 PM
Vitalij Bredun ♡ Python Petersburg
Vitalij Bredun ♡ Python Petersburg - avatar