Local Variables Cannot Be Used in The Global Scope: Spam Spam
Local Variables Cannot Be Used in The Global Scope: Spam Spam
was called. Local variables are also stored in frame objects on the call
stack.
Scopes matter for several reasons:
Code in the global scope, outside of all functions, cannot use any
local variables.
However, code in a local scope can access global variables.
Code in a function’s local scope cannot use variables in any other
local scope.
You can use the same name for different variables if they are in
different scopes. That is, there can be a local variable named spam
and a global variable also named spam.
def spam():
➊ eggs = 31337
spam()
print(eggs)