sorry I'm new to python and still trying to wrap my head around few fundamentals. I know lists are mutable objects in python, but can't understand how the two functions below handle lists, and why one changes the list itself and the other doesn't
def f(x, y):
x.append(x.pop(0))
x.append(y[0])
return x
>>> a=[1,2,3]
>>> b=[1,2]
>>> f(a,b)
>>> [2, 3, 1, 1]
>>> a
>>> [2, 3, 1, 1]
def f(x, y):
y = y + [x]
return y
>>> a=[1,2,3]
>>> f(4,a)
>>> [1, 2, 3, 4]
>>> a
>>> [1, 2, 3]
Thank you