I am confused with the python's design of global variables, it seems quite different for a normal global variable and a global list, consider the following code:
global_list = []
global_var = 0
def foo():
for i in range(10):
global global_var # without this, error occurs
global_var += 1
global global_list # without this, fine!
global_list.append(i)
foo()
print(global_list)
print(global_var)
The code is quite self-explained, I would like to know why this is the case, what is the logic behind that. Besides, I've also tested a dictionary, it behaves like a list. What about other stuff, such as a class instance or something...