Graphing your data using package memory_graph can help your understanding of the Python Data Model:
import memory_graph as mg # see link above for install instructions
arr1 = []
arr2 = [1, 2]
arr1.append(arr2)
arr2[0] = 5 # change of value
mg.render(locals(), 'graph1.png') # graph the local variables
A change of a value of mutable type list effects all that share the value, arr1
and arr2
.
arr2 = [6] # name rebinding
print(arr1)
mg.render(locals(), 'graph2.png') # graph the local variables
Name rebinding only effects the arr2
variable that is rebound.