I had heard about passing by reference vs. passing by value. Here is a case of passing by reference.
In [76]: a=[1,2]In [77]: b=aIn [78]: b.append(3)In [79]: aOut[79]: [1, 2, 3]
That’s not what I was looking for. I was hoping to get 'b' to be [1, 2, 3] leaving 'a' unchanged. Oops. It passed 'a' to 'b' by reference so any changes to 'b' affected 'a'. So… need a copy. Simplest way I’ve seen of copying an array in python so far is to use [:].
Learn Python in 10 minutes | Poromenos’ Stuff
A useful use of the array range colon is to copy an array:
newary = oldary[:]

Succinct and helpful. Thank you.
Comment by ertyseidel — June 25, 2010 @ 3:18 pm
#add empty mutation also copies
a = [1,2]
b = a + []
b.append(3)
print a
[1,2]
Comment by Aduen (@Aduen) — March 26, 2012 @ 3:20 pm