""" File: funarg3.py It is possible to return two local functions simultaneously as a pair. These returned functions share a closure. Changes made by the returned function f to the nonlocal variable count is seen by returned function g. """ def fgen(w,x): def inc_a(y): nonlocal count count += 1 print("count=", count) return y + a def inc_b(y): nonlocal count count += 1 print("count=", count) return y + b a = w b = x count = 0 return (inc_a, inc_b) (f,g) = fgen(3,17) print("Calling f():") print(f(1)) print(f(2)) print(f(3)) print("Calling g():") print(g(1)) print(g(2)) print(g(3))