I am trying to understand how a list is processed when passed as an argument to a function. So, I did the following:
I initialized the list:
ll = [1,2,3,4]
and define the function:
def Foo(ar):
ar += [11]
I passed a list of functions:
Foo(ll)
and when I print it, I got:
print ll
So far so good.
Now I have changed the function to reset the list so that it has only one element:
def Foo(ar):
ar = [11]
I remembered the syntax:
Foo(ll)
and when I reprinted it, he led to the same list:
print ll
I thought the list was passed as a link; therefore, everything we do with the list inside the function will always change the original function passed from the main program. Therefore, for case (2), I expected the following result:
print ll
Did I miss something?
source
share