#!/usr/bin/python
print('Simple Assignment')
shoplist = ['apple','mango','carrot','banana']
mylist = shoplist #这里只是把mylist也指向了shoplist列表,程序中现在只有一个列表,mylist相当于别名
del shoplist[0]
print('shoplist is',shoplist)
print('mylist is',mylist)
print('Copy by making a full slice')
mylist = shoplist[:] #这是复制操作,程序中此时有两列表,mylist和shoplist各代表一个列表
del mylist[0]
print('shoplist is',shoplist)
print('mylist is',mylist)
结果:
~/Note/python # ./5refrence.py
Simple Assignment
shoplist is ['mango', 'carrot', 'banana']
mylist is ['mango', 'carrot', 'banana']
Copy by making a full slice
shoplist is ['mango', 'carrot', 'banana']
mylist is ['carrot', 'banana']