+ 1

Kindly explain this part!

THE PART WHICH I HAVE HIGHLIGHTED WITH ASTERISK...PLZ EXPLAIN THT class Queue: def __init__(self, contents): self._hiddenlist = list(contents) def push(self, value): self._hiddenlist.insert(0, value) def pop(self): return self._hiddenlist.pop(-1) ***** def __repr__(self): return "Queue({})".format(self._hiddenlist)*****

27th Sep 2020, 3:36 PM
Srishti - avatar
2 Answers
+ 4
U need the __repr___ to print an instance of the class with a simple print(instance)
27th Sep 2020, 4:08 PM
Oma Falk
Oma Falk - avatar
+ 3
Yes. As said it's *Called automatically when an object is created so there in code it returning objects contents.. Check by this.. print(Queue("12345"))
27th Sep 2020, 4:21 PM
Jayakrishna 🇮🇳