""" File: local1.py Python allows local functions to be defined. Below, the local function B alters the value of the local variable a of the enclosing function A. """ def A(n): def B(y): nonlocal a a = a + 1 return y + a a = 2*n print("a = " + str(a)) x = B(5) x = B(x) print("a = " + str(a)) return x r = A(2) print ("r = " + str(r))