So, I just ran into some unexpected behavior regarding While Loops in Python.
Consider the following Code:
num = 0
array = [0, 1, 2]
while num < 5:
newarray = array
newarray[0] += 1
print newarray
print array
num += 1
I expect newarray to be reset to array each iteration and array to stay the same. However in the print function they both change their values. I have already solved this problem with the copy module, but I'm left wondering, why is it behaving that way?
If you replace the array with an int it behaves as I would expect.