0

I am confused on this code. I think that I am taking my orginal list to the temp so it should not be changed. Could someone expain this ?

a = [1,2,3]
b= a
b.remove(1)
print a
#Output [2,3]

Why the orginal list a changed ? Is python work with references like pointers ?

Batuhan B
  • 1,835
  • 4
  • 29
  • 39
  • in your code `a` and `b` are aliases for the same list. Yes -- it is all pointers behind the scenes. – John Coleman Aug 09 '15 at 22:12
  • All values (even integers) are objects in Pythons, and all variables contain references to objects. Some objects can't be changed in place (integers can't) so it kinda looks like those are pass-by-value, but they're not.. Everything is pass-by-reference. – kindall Aug 09 '15 at 22:21

0 Answers0