What will be the output of the following code?
queue= [1,2,3]
queue.append(4)
print(queue.pop(0))
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.
Related questions:
2026: 26 May Shift 1
2026: 21 May Shift 1
2025: 22 May Shift 1
2025: 27 May Shift 2