I'm having trouble understanding how python pointers/ references work.
Take for example,
my_list = [1,2,3,4]
A = [my_list]*3
print("Before the change", A)
my_list[2]=45
print("After the change ", A)
The code will print "After the change [[1, 2, 45, 4], [1, 2, 45, 4], [1, 2, 45, 4]]"
However, if I do my_list = [10,20,30,40]
, A will not change even though, as I understand it, A points to the reference of my_list. What is actually happening? Is A pointing to the object [1,2,3,4]
or to the variable my_list?
Note: I use pointer and reference to mean the same thing(Please tell me if it doesn't...)