Local functions in Python
问题 In the following Python code, I get an UnboundLocalError . As I understand it, local functions share the local variables of the containing function, but this hardly seems to be the case here. I recognise that a is an immutable value in this context, but that should not be a problem. def outer(): a = 0 def inner(): a += 1 inner() outer() It would seem that the inner function has received copies of all the references in the parent function, as I do not get the UnboundLocalError exception if the