Medium
Engineer
SpeedRun
closures
scope
lambdas
Python: Late-Binding Closures in a Loop
+200 XP · 5 min · attempt 1
Problem
What does this print?
funcs = [lambda: i for i in range(4)]
print([f() for f in funcs])
Enter the exact list output, e.g. `[0, 1, 2, 3]`.
Starter
# Closures in Python capture variables by reference, not by value.
# After the comprehension finishes, what is the final value of `i`?
Your answer
Playing as a guest — you'll be asked for a display name on submit. Log in to keep your XP across devices.