-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
Introduction to Python
Python Basics
Python Syntax
Python Comments
Python Variables
Python Data Types
Python Casting
Python I/O
Python Operators
Cotrol Structures
Data Structures
Python Strings
Python Lists
Python Tuples
Python Dictionaries
Python Sets
Python Arrays
Python Bytes and Bytearray
Date and Time
Functions and Module
File Handling
Python OOP
Advanced Concepts
Python Scope
Python Modules
Python JSON
Python RegEx
Python PIP
Python Try...Except
Python String Formatting
Python User Input
Python VirtualEnv
Python Math
Python DSA
Python DSA
Lists and Arrays
Python Stacks
Python Queues
Linked Lists
Python Hash Tables
Python Trees
Python Binary Trees
Binary Search Trees
Python AVL Trees
Python Graphs
Searching Algorithms
Sorting Algorithms
A Queue is a linear data structure that follows the FIFO (First In, First Out)** principle — the first element added is the first one to be removed.
Python doesn’t have a built-in queue type, but you can implement queues using:
List
collections.deque
(recommended)
queue.Queue
(for multithreading)
queue = []
# Enqueue
queue.append('a')
queue.append('b')
queue.append('c')
print(queue) # ['a', 'b', 'c']
# Dequeue
queue.pop(0) # Removes 'a'
print(queue) # ['b', 'c']
❗ Lists are not ideal for queues as removing from the front is slow for large data.
collections.deque
(Recommended)from collections import deque
queue = deque()
queue.append('apple') # Enqueue
queue.append('banana')
queue.append('cherry')
print(queue.popleft()) # Dequeue → apple
print(queue) # deque(['banana', 'cherry'])
✅ deque
is fast and efficient for queue operations.
print("Front:", queue[0])
print("Rear:", queue[-1])
if not queue:
print("Queue is empty")
else:
print("Queue is not empty")
Print queues
Customer service systems
Task scheduling
Breadth-first search in trees/graphs
Q1. Write a Python program to create a queue and add 5 names to it.
Q2. Write a Python program to remove 2 elements from the queue using popleft()
from collections.deque
.
Q3. Write a Python program to print the first and last item in the queue.
Q4. Write a Python program to implement a queue using a list (with append()
and pop(0)
).
Q5. Write a Python program to check if the queue is empty before removing an item.
Q6. Write a Python program to enqueue items in order: A, B, C — then dequeue one and print the result.
Q7. Write a Python program to use len()
to print the current size of the queue.
Q8. Write a Python program to clear all elements from the queue.
Q9. Write a Python program to create a number queue and calculate the sum of all items.
Q10. Write a Python program to simulate a ticket booking queue where users are served in the order they arrive.
Introduction to Python
Python Basics
Python Syntax
Python Comments
Python Variables
Python Data Types
Python Casting
Python I/O
Python Operators
Cotrol Structures
Data Structures
Python Strings
Python Lists
Python Tuples
Python Dictionaries
Python Sets
Python Arrays
Python Bytes and Bytearray
Date and Time
Functions and Module
File Handling
Python OOP
Advanced Concepts
Python Scope
Python Modules
Python JSON
Python RegEx
Python PIP
Python Try...Except
Python String Formatting
Python User Input
Python VirtualEnv
Python Math
Python DSA
Python DSA
Lists and Arrays
Python Stacks
Python Queues
Linked Lists
Python Hash Tables
Python Trees
Python Binary Trees
Binary Search Trees
Python AVL Trees
Python Graphs
Searching Algorithms
Sorting Algorithms