As I have been told that when we pass a list to a function, the list is passed by reference.
So, if I have
>>> a = [0]
>>> def change(a):
... a += [1]
The following works as expected.
>>> change(a)
>>> a
[0, 1]
But if I have the function change
as
>>> def change(a):
... a = [1]
and a = [0]
. Then if I do,
>>> change(a)
The result is as following
>>> a
[0]
This means that here, the list was not passed by reference.
Is this behaviour expected? I am using Python 2.7.6