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

Quiz: Scope and Closures · Question 6 of 10

What does this print? (code)

What does this print?

fs = [lambda: k for k in range(4)]
print(fs[0]())
  1. A.0
  2. B.1
  3. C.3
  4. D.An error
Answer & explanation

Correct answer: 3

Late binding: every lambda reads k when called, and k is 3 by then.

Can you get the rest right without peeking?

Take the timed Quiz: Scope and Closures quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →