3 ms·
By using Python3's nonlocal statement. def outer(): a, b = 1, 2 def inner(): nonlocal a a, b = 3, 4 print('inner a
by gvalkov 13y ago
By using Python3's nonlocal statement.
def outer():
a, b = 1, 2
def inner():
nonlocal a
a, b = 3, 4
print('inner a: ', a)
print('inner b: ', b)
inner()
print('outer a: ', a)
print('outer b: ', b)
outer()
# inner a: 3
# inner b: 4
# outer a: 3
# outer b: 2
I find Python's scoping rules to be quite sane.