Pass immutable and mutable value into function
![Pass immutable and mutable value into function](http://www.java2s.com/Code/PythonImages/Passimmutableandmutablevalueintofunction.PNG)
def changer(x, y):
x = 2 # changes local name's value only
y[0] = 'spam' # changes shared object in place
X = 1
L = [1, 2]
changer(X, L) # pass immutable and mutable
print X, L
L = [1, 2]
changer(X, L[:]) # pass a copy
print X, L
Related examples in the same category