Guest User

Owl

a guest
Mar 19th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. L1 = [2] # Creates object 2(type int) and put it in L1(list) at [0] index
  2. L2 = [L1, L1] # Put reference links in L2(list) to L1(list) at [0] index and [1] index]
  3. print 'L2 =', L2 # Prints L2(list)
  4. L1[0] = 3 # Creates object 3(type int) and re-assign [0] index in L1(list) to it
  5. print 'L2 =', L2 # Prints L2(list)
  6.  
  7. ##
  8. # L2(list) changing because it contain 2 reference links to L1(list) not values
  9. # one refernce at [0] index another one at [1] index
  10. # to avoid mutating u should assign value of L1 to L2 at index's [0] and [1]
  11. # L2 = [L1[0], L1[0]]
  12. ##
Advertisement
Add Comment
Please, Sign In to add comment