Scopes may nest arbitrarily, enclosing function def statements are searched when names are referenced:
def f1(): x = 99 # w w w .jav a2s . co m def f2(): def f3(): print(x) # Found in f1's local scope! f3() f2() f1()