2 ms·
This is fixed in Python 3 with the nonlocal keyword. In Python 2, the idiomatic work-around is to have x be list of one item: def f(): x = [0]
by js2 9y ago
This is fixed in Python 3 with the nonlocal keyword. In Python 2, the idiomatic work-around is to have x be list of one item:
def f():
x = [0]
def add(amt):
x[0] += amt
add(10)
return x[0]