🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Threads and Context Switching: all 10 questions

Quiz: Threads and Context Switching · Question 8 of 10

What does this print? (code)

What does this print?

import threading
data = []
t = threading.Thread(target=lambda: data.append(1))
t.start()
t.join()
print(len(data))
  1. A.0
  2. B.1
  3. C.2
  4. D.Error
Answer & explanation

Correct answer: 1

The thread appended to the same list that the main thread then printed.

Can you get the rest right without peeking?

Take the timed Quiz: Threads and Context Switching quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →