Scope

Applies to: general, python

Scope is the region of code where a name is visible. A variable defined inside a function is local to it and vanishes when it returns; names defined outside are broader. Scope keeps parts of a program from clobbering each other's variables.

x = 1            # module scope
def f():
    y = 2        # local to f; invisible outside
    return x + y # can read the outer x

See also: variable, function