I am trying to understand the variable scope in Python (3.x), but below is an example of code that does not work and I am not sure why.
def function_a(A):
function_b()
def function_b():
print(A)
function_a(1)
Which results in NameError: name 'A' is not defined
So, the way I would think it works is that function_a() and function_b() are definid. Afterwards I run function_a() where A gets assigned the value of 1.
So in the scope of function_a() the variable A=1 exists.
Then function_b() gets called and is meant to print the value of variable A. A does not exist in the scope of function_b(). Hence I would expect it to look a level higher, which would be the scope of function_a() because function_b() is run within function_a().
But clearly, I am getting that wrong. What actually happens?