1.FIFO principle
A queue is First-In-First-Out: the item that has been waiting longest is always the first one served — the exact opposite of a stack's LIFO order.
Key features
- enqueue adds to the back; dequeue removes from the front — the two ends are never the same one
- Contrast with a stack (LIFO): a queue always serves the OLDEST item first, a stack always serves the NEWEST
- collections.deque is the practical Python queue — append() to enqueue, popleft() to dequeue, both O(1)
Command
from collections import deque
queue = deque()
queue.append('a')
queue.append('b')
queue.append('c')
print(queue.popleft()) # 'a' — the earliest-enqueued item, out first
print(queue) # deque(['b', 'c']) — 'c' arrived last and waits behind 'b'FIFO means the first thing enqueued is the first thing dequeued — picture a line of people, not a stack of plates.