pair makes two inner functions that use the same variable.
def pair():
v = 0
def get():
return v
def put(x):
nonlocal v
v = x
return get, put
g, p = pair()
p(7)
print(g(), pair()[0]())
What does the program print?Log in to join the discussion.
Loading…