+ 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?
1 Respuesta
+ 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.