79562579

Date: 2025-04-08 16:24:20
Score: 0.5
Natty:
Report link

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

graph1.png

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

graph2.png

Name rebinding only effects the arr2 variable that is rebound.

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: bterwijn