""" File: local2.py Python allows local functions to be defined. Local functions are not accessible outside the function where it is defined. """ 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 = B(2) # <--- is an error