Queue: the queue is FIFO.
Import queueq = queue. queue () Q. put (1) Q. put (2) Q. put (3) Q. put (4) print (Q. get () print (Q. get () print (Q. get () print (Q. get ())
STACK: the stack is advanced and later.
Import queueq = queue. lifoqueue () Q. put (1) Q. put (2) Q. put (3) Q. put (4) print (Q. get () print (Q. get () print (Q. get () print (Q. get ())
Priority queue: the priority queue is determined based on the priority. If the priority is the same, it is output according to the data ASCII code.
Import queueq = queue. priorityqueue () Q. put (10, 'B') Q. put (30, 'A') Q. put (13, 'F') Q. put (-3, 'k') Q. put (-3.5, 'C') Q. put (-7.5, 'H') print (Q. get () print (Q. get () print (Q. get () print (Q. get () print (Q. get () print (Q. get ())
Output result:
(-7.5, 'H') (-3.5, 'C') (-3, 'k') (10, 'B') (13, 'F') (30, 'A ')
The smaller the number, the higher the priority.
The same priority. Compare the ASCII code of the subsequent data.
Queue queue, stack lifoqueue, priority queue priorityqueue