deque.append() vs deque.appendleft()
deque.append() and deque.appendleft() are both Python Collections Module APIs, and choosing between them is a common point of confusion. This page compares their syntax, parameters, return values, and typical use cases so you can pick the right one. deque.append(): Adds x to the right side of the deque. Its syntax is deque.append(x), and it returns none deque.appendleft(): Adds x to the left side of the deque. Its syntax is deque.appendleft(x), and it returns none Example of deque.append(): d = deque([1,2])
d.append(3) # deque([1,2,3]). Example of deque.appendleft(): d = deque([2,3])
d.appendleft(1) # deque([1,2,3]). Read the full references for deque.append() and deque.appendleft() to see parameters, edge cases, and example code side by side. Other Collections Module APIs worth comparing: collections.deque(), deque.pop(), deque.popleft(), deque.extend(), deque.extendleft(), deque.rotate(). Both belong to the Collections Module category in the Python Reference documentation. Try both in the Python playground to see the behavioral difference live.