From the course: Programming Foundations: Data Structures
Unlock this course with a free trial
Join today to access over 25,600 courses taught by industry experts.
What is a queue? - Python Tutorial
From the course: Programming Foundations: Data Structures
What is a queue?
- Like with lists, queues represent a series of ordered objects, but how we access, add, and remove items is slightly different. Think of a queue at an amusement park or a line of people at the store. A queue has a front and a back, and it operates the same way in code. Elements are inserted at the end of the queue and removed from the beginning. Just like in a real line, the first person in is the first person out, and the last person in is the last one to leave. This behavior is known as FIFO, or first in, first out. In queue operations, you'll often hear the terms enqueue and dequeue. Enqueueing refers to adding an item to the back of the queue, while dequeueing means removing the item at the front. You can also use peek to view the first item in the queue without removing it. This is the next item to be dequeued. In Python, there's a built-in tool we can use to store and manage data as a queue. Let's take a look.