I understand this code:
test_variable = 0def test_function(): test_variable = 1test_function()print(test_variable)Because the test_function does not declare a global test_variable, the actual global test_variable is not changed, so the output is 0.
However, it seems to work differently if I use a dictionary:
resources = {"water": 300,"milk": 200,"coffee": 100,}def test_function(): resources['water'] = 500test_function()print(resources)Now I get the result: {'water': 500, 'milk': 200, 'coffee': 100}.
Why did the value for 'water' inside the resources dictionary change, even though the new test_function still does not use global?