underneath the hoodpython implements queues on top of the collections deque data structure deques are advanced data structures that permits efficient access to both ends of the collection it provides more flexible interface than is exposed by queue refer you to the python documentation if you' like to experiment more with it lifo queues lifo (last in first outqueues are more frequently called stacks think of stack of papers where you can only access the top-most paper you can put another paper on top of the stackmaking it the new top-most paperor you can take the top-most paper away to reveal the one beneath it traditionallythe operations on stacks are named push and popbut the python queue module uses the exact same api as for fifo queuesput(and get(howeverin lifo queuethese methods operate on the "topof the stack instead of at the front and back of line this is an excellent example of polymorphism if you look at the queue source code in the python standard libraryyou'll actually see that there is superclass with subclasses for fifo and lifo queues that implement the few operations (operating on the top of stack instead of front and back of deque instancethat are critically different between the two here' an example of the lifo queue in actionfrom queue import lifoqueue stack lifoqueue(maxsize= stack put("one"stack put("two"stack put("three"stack put("four"block=falsetraceback (most recent call last)file ""line in stack put("four"block=falsefile "/usr/lib /python /queue py"line in put raise full queue full stack get('threestack get(