ds_reference.py 657 B

123456789101112131415161718192021222324
  1. print('Simple Assignment')
  2. shoplist = ['apple', 'mango', 'carrot', 'banana']
  3. # mylist is just another name pointing to the same object!
  4. mylist = shoplist
  5. # I purchased the first item, so I remove it from the list
  6. del shoplist[0]
  7. print('shoplist is', shoplist)
  8. print('mylist is', mylist)
  9. # Notice that both shoplist and mylist both print
  10. # the same list without the 'apple' confirming that
  11. # they point to the same object
  12. print('Copy by making a full slice')
  13. # Make a copy by doing a full slice
  14. mylist = shoplist[:]
  15. # Remove first item
  16. del mylist[0]
  17. print('shoplist is', shoplist)
  18. print('mylist is', mylist)
  19. # Notice that now the two lists are different