Skip to main contentSkip to solution

What will be the output of the following code?

queue= [1,2,3]

queue.append(4)

print(queue.pop(0))

Solution

✅ Correct Option: 1

append(4) adds 4 at the end, so the list becomes [1, 2, 3, 4].

pop(0) removes and returns the element at index 0, which is 1. So print displays 1, and the list becomes [2, 3, 4].


Option 4: 4 is the item that append adds, but pop(0) takes from the front, not the end.

Plain pop() with no index would remove the last item and print 4.

Keyboard Shortcuts

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