Possible Duplicate:
Python: How do I pass a variable by reference?
I want to test the parameter passing behavior in python function by the following 2 functions:
In:
def f(a):
a[0]=3
print 'in f ',a
a=[1,2]
print 'ori ',a
f(a)
print 'now ',a
It turned out the "a" has been modified after returning from f().
However, in:
import numpy as np
def f(a):
a=np.array(a,np.float)
print 'in f ',a
a=[1,2]
print 'ori ',a
f(a)
print 'now ',a
I found that "a" was not changed to numpy array after returning from f().
Can somebody give some explanations?