Queue · Class 12 · CBSE · Science Computer Science

What will be printed by the following Python code? q = []; q.append(10); q.append(20); q.pop(0); q.append(30); print(q[0], q.pop(0))

Practice question from Queue (Class 12 · CBSE · Science Computer Science), with the correct answer and a step-by-step solution.

hard · MCQ · Q-525CA3

What will be printed by the following Python code? q = []; q.append(10); q.append(20); q.pop(0); q.append(30); print(q[0], q.pop(0))

  1. A.10 10
  2. B.20 20Correct answer
  3. C.20 30
  4. D.30 30

Solution

After removing 10, the queue contains [20]. Appending 30 gives [20, 30]; therefore, q[0] is 20 and removing the front element also returns 20.

More from Queue

All of Queue

Practise more Computer Science

Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.

Start practising free

Free to start · No credit card needed