A variable defined in one part of a program does not need to be known in other parts. All program units to which a certain variable is known are called the scope of that variable. We'll first give an example. Let's consider the two nested functions:
e = 3 def my_function(in1): a = 2 * e b = 3 in1 = 5 def other_function(): c = a d = e return dir() print(f""" my_function's namespace: {dir()} other_function's namespace: {other_function()} """) return a
The execution of my_function(3) results in:
my_function's namespace: ['a', 'b', 'in1', 'other_function'] other_function's namespace: ['a', 'c', 'd']
The variable e is in the namespace of the program unit that encloses the function my_function. The variable...