I have this piece of code in Python:
def sortList(x):
x.sort()
print "Values inside the function: ", x
return
mylist = [100,20,30];
sortList(mylist);
print "Values outside the function: ", mylist
The output is:
Values inside the function: [20, 30, 100] Values outside the function: [20, 30, 100]
Now, instead of writing x.sort()
if I write x=[1,2,3]
then the output is:
Values inside the function: [1, 2, 3] Values outside the function: [100, 20, 20]
So why does the value of the array "mylist" change from inside the function? And that too only when I perform some operation on it, and not when I assign completely new value to it?
Thanks!