...

/

Puzzle 11: Explanation

Puzzle 11: Explanation

Let’s find out how closure works in Python and how to fix this bug.

We'll cover the following...

Let’s try it!

Try executing the code below to verify the result:

Press + to interact
display = []
buttons = []
for n in range(10):
# A button is a function called when user clicks on it
buttons.append(lambda: display.append(n))
btn = buttons[3]
btn()
print(display)

Explanation

Most people ...

Access this course and 1400+ top-rated courses and projects.