Question:medium

Which of the following function can be used to insert a new element at the end of a queue?
(Assume a queue named myQueue has been created by assigning an empty list i.e., myQueue = list())

Show Hint

When implementing a queue using a Python list:
- Use list.append(element) to insert elements at the rear (Enqueue).
- Use list.pop(0) to remove elements from the front (Dequeue).
Updated On: Jun 11, 2026
  • 1
  • 2
  • 3
  • 4
Show Solution

The Correct Option is B

Solution and Explanation


Step 1: Understanding the Question:

The question asks to identify the correct Python function code to implement the enqueue operation (inserting a new element at the end of a queue) when the queue is represented using a Python list.

Step 2: Key Formula or Approach:

- A Queue is a First-In, First-Out (FIFO) linear data structure where elements are added at one end (rear) and removed from the other end (front).
- When using a Python list to represent a queue, the end of the list represents the rear of the queue.
- We need to identify the correct built-in Python list method that appends an element to the end of a list.

Step 3: Detailed Explanation:

- Let us analyze the standard list methods in Python:
- append(element): This is a built-in Python list method that adds a single element to the very end of the list. Thus, calling myQueue.append(element) correctly inserts the element at the rear of the queue.
- add(element): This is a method used for Python sets, not lists. Calling this on a list raises an AttributeError.
- push(element): This is not a built-in method for Python lists. While used conceptually in stacks, it does not exist in standard Python list implementations.
- insert(): The insert() method requires two arguments: an index and the element, in the form insert(index, element). Calling myQueue.insert(element) with only one argument raises a TypeError.
- Therefore, the only syntactically and logically correct block of code is Option (B).

Step 4: Final Answer:

The correct function to insert a new element at the end of the queue list is the one using the append() method.
Hence, option (B) is the correct choice.
Was this answer helpful?
0


Questions Asked in CUET (UG) exam