I have the following code:
tree = {'nodes':[1,2,3],'root':[1]}
nodes = tree['nodes']
nodes.remove(2)
print(tree['nodes'])
print(nodes)
The output is the following:
[1, 3]
[1, 3]
My question may be stupid but I do not understand why remove
method caused that tree
variable has changed too?
I thought that when I create a new variable like nodes
in the example above, then any method applied on this variable will affect only this variable.
From this example, I can conclude that it had an impact on a tree
variable too.
Is it related to the global and local variables somehow?