Fixing Late Binding With a Default Argument
def make_funcs():
broken = []
fixed = []
for i in range(3):
broken.append(lambda: i * 10)
fixed.append(lambda i=i: i * 10)
return broken, fixed
broken, fixed = make_funcs()
print([f() for f in broken], [f() for f in fixed])
What does this print?
Sign in to answer questions and track your progress
Sign In