Dec-13-2020, 05:32 PM
I don't like how Python handles scope. Inner functions cannot access the outer function's variables when in any other language, they can. Here is an example closure in which I had to use the nonlocal keyword in order to have access to the outer functions variable of the same name. The global, function and block namespaces should be automatic. Keywords like Global and nonlocal; are they really necessary?
def my_func(): count = 0 def inner_func(): nonlocal count count += 1 return count return inner_func a = my_func() print(a()) print(a()) print(a())
OUTPUT: 1 2 3