+ 1

Hiddenlist

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) queue = Queue([1, 2, 3]) print(queue) queue.push(0) print(queue) queue.pop() print(queue) print(queue._hiddenlist)-how do I define this please?

8th Mar 2018, 5:36 AM
Adaobi
1 Answer
+ 1
Could you be more specific? if you want tout declare a "private" attribute, use self.__hiddenlist . Athough it remains accessible with queue._Queue__hiddenlist still.
7th Apr 2018, 4:16 PM
Loïc Mahé
Loïc Mahé - avatar