Re:Go: Redefining For Loop Variable Semantics
by dekhn on Tuesday October 11, 2022 @11:09AM
(#33164266)
I guess this is confusing but i just think of it as capturing the reference to i, not the value of i. It would be nice if python had a nice way to deal with this as many people also trip over:
def fun(initial_empty_list=[]):
where initial_empty_list is a reference captured at function definition time, not a new value initialized on each call to the function.
def fun(initial_empty_list=[]): where initial_empty_list is a reference captured at function definition time, not a new value initialized on each call to the function.