Using the following code
def test(n):
n=n*2
print("inside test",n)
n=[9]
print("before the call", n)
test(n)
print("after the call", n)
the ouput is:
before the call [9]
inside test [9, 9]
after the call [9]
I thought that the passing of list parameters in functions was made by reference and modified the calling parameters.It is not the case here: suprising. I was expecting:
before the call [9]
inside test [9, 9]
after the call [9, 9]
If I use the append
method instead of n=n*2
, the effect is OK.
Can anyone clarify this point, please?