Suppose I have this function
>>>a=3 >>>def num(a): a=5 return a >>>num(a) 5 >>>a 3
The value of a does not change.
Now consider this code:
>>> index = [1] >>> def change(a): a.append(2) return a >>> change(index) >>> index >>> [1,2]
In this code, the index value changes. Can someone explain what happens in these two codes. According to the first code, the index value should not change (ie, index = [1] should remain).
source share