+ 2
I don't understand pop and push function here? Python
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)
2 Respostas
+ 10
push() and pop) are instance methods of a class Queue. push() inserts a new value at index 0 (left side) to the _hiddenlist, pop() removes the last value of the list. pop() and insert() are common list methods.
+ 3
Lothar said all, what is to say, but read his words carefully:
Did u recognize that he mentioned the self defined method pop()
AND the standard method pop()?
we have two pop() functions here.