Skip to main contentSkip to solution

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())

Solution

✅ Correct Option: 2

A queue follows FIFO, so a new element is added at the rear (end). Since myQueue is a Python list, the list method append(element) adds an item at the end, which is exactly what enqueue needs.


Option 1: add() is a method of sets, not lists.

Option 3: push() is a common stack term, but Python lists have no such method.

Option 4: insert() needs two arguments (index and element), so insert(element) raises an error.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question