← 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]())
- A.0
- B.1
- C.3
- 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 →