The reason you are getting this is because when you performed this assignment in your function:
A = [7, 8, 9]
The interpreter will now see A as a locally bound variable. So, what will happen now, looking at this condition:
if(len(A)>0):
Will actually throw your first UnboundLocalError exception, because, due to the fact, as mentioned, you never declared global A in your b function and you also created a locally bound variable A = [7, 8, 9], you are trying to use a local A before you ever declared it.
You actually face the same issue when you try to do this:
A.remove(2)
To solve this problem with respect to your code, simply declare the global A back in your b() function.
def b():
global A
if(len(A)>0):
A=[7,8,9]
else:
if(A[3]==4):
A.remove(2)
However, the better, ideal and recommended way to do this is to not use global and just pass the arguments to your function
A = [1, 2, 3, 4]
def main(list_of_things):
# do whatever operations you want to do here
b(list_of_things)
def b(list_of_things):
# do things with list_of_things
main(A)