collections.deque() vs deque.append()
collections.deque() and deque.append() 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. collections.deque(): Returns a double-ended queue (deque) with efficient O(1) appends/pops from both ends. Its syntax is collections.deque([iterable], maxlen=None), and it returns deque object deque.append(): Adds x to the right side of the deque. Its syntax is deque.append(x), and it returns none Example of collections.deque(): from collections import deque
d = deque([1,2,3], maxlen=5)
d.append(4); d.appendleft(0)
list(d) # [0,1,2,3,4]. Example of deque.append(): d = deque([1,2])
d.append(3) # deque([1,2,3]). Read the full references for collections.deque() and deque.append() to see parameters, edge cases, and example code side by side. Other Collections Module APIs worth comparing: deque.appendleft(), deque.pop(), deque.popleft(), deque.extend(), deque.extendleft(), deque.rotate(). Both belong to the Collections Module category in the Python Reference documentation.