I am just started learning Python am getting bit confused after seeing the output of following program:
#!/usr/bin/python
# Function definition is here
def changeme( mylist ):
"This changes a passed list into this function"
mylist = [1,2,3,4]; # This would assig new reference in mylist
print "Values inside the function: ", mylist
return
# Now you can call changeme function
mylist = [10,20,30];
changeme( mylist );
print "Values outside the function: ", mylist
Values inside the function: [1, 2, 3, 4]
Values outside the function: [10, 20, 30]
Why is Values outside the function: [10, 20, 30]
, and not [1, 2, 3, 4]
since we are passing the argument to the function by reference?