I have just started python and came across something kind of strange.
The following code assigns a co-ordinate of x=1 and y=2 to the variable test. The test2 variable assigns itself the same value as test and then the [x] value for test2 is changed to the old [x] value minus 1. This works fine, however, when the last part is executed, not only does it minus 1 from the [x] value in test2, it does the same to the [x] value in the test variable too.
test = [1,2];
test2 = test;
test2[1] = test2[1] - 1;
I found doing the following worked fine but I still don't understand why the first method changes the test value as well as the test2 value.
test = [1,2];
test2 = test;
test2 = [test2[0] -1 ,test2[1]];
Could someone please explain why this happens.
Thank You TheLorax