I can't understand why this simple code produces the results it does, I have tried to search for another similar question but I've not been sure on the correct vocabulary to use. Here is the code in question.
def test(f):
f.append(0)
f.append(0)
return f
i = [0] * 6
f = i
print(i)
f = test(f)
print(i)
The result it produces in python 3.7
[0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0]
I'm no expert in python but I really don't understand how the value of i is dependant on the value of f. The value of f is dependant at the start on the i but that way only. I would have expected to see both the lists to be identical when printed. The function doesn't recognise the i list and yet changes it either side of the function.
Obviously when the f list is printed the results are expected but I was hoping to explain what was happening here with i.