3 ms·
It's not quite that bad. Within a function, Python resolves scope statically, and the "del" statement terminates binding, but not the scope. If a variable is a
by duckerude 8y ago
It's not quite that bad. Within a function, Python resolves scope statically, and the "del" statement terminates binding, but not the scope.
If a variable is assigned to somewhere in the function, even later in the function, or in an unreachable branch, accessing it will use the function's scope. If the variable doesn't have a value you get an UnboundLocalError.
Even after you del a variable, accessing it will raise an UnboundLocalError rather than look in another scope.