I have the following code:
def proc2(p):
p=p+[1]
y=[2,5]
proc2(y)
print(y)
z=[2,5]
z=z+[1]
print(z)
The output of the code is:
[2, 5]
[2, 5, 1]
I understand that y is not modified to [2,5,1]
. But, y is reassigned to a new list, which is [2,5,1]
, right? Then why does y still refer to the original value? If the value of z has changed, why not y?
P.S. I have just asked a question which is almost the same as this one. That question has been marked as a duplicate of another question. However, I think they are a bit different. That is why I'm posting my question again. I think I must have missed something about function.