4 ms·
Right. In this example lambda does not capture i at all. You would need something like funcs.append(lambda i=i: print(i))
by InfamousRece 3y ago
Right. In this example lambda does not capture i at all. You would need something like
funcs.append(lambda i=i: print(i))
- assbuttbuttass 3y agoNo, it definitely captures i Maybe this example where it returns the closures from a function is convincing? def fs(): funcs = list() for i in range(10): funcs.append(lambda: print(i)) return funcs for f in fs(): f()