Multi-scoped variables
-
ClosureDynamicPL/Python 2019. 11. 7. 17:09
1. Overview Closure can be consist of a function plus an extended scope that contains the free variables. 2. Description 2.1 Free Variable and Inner Function Functions defined inside another function can access the outer (nonlocal) variables def outer(): x = [1, 2, 3] print('outer:', hex(id(x))) def inner(): print('inner:', hex(id(x))) print(x) return inner fn = outer() fn() x is a free variable..