print(‘The simple assignment‘) shoppingList = [‘chicken‘,‘mango‘,‘apple‘,‘banana‘] myList = shoppingList print(‘Before any action‘) print(‘The shopping list is‘,shoppingList) print(‘my list is‘,myList,‘\n‘) print(‘Del the first item from the shopping list‘) del myList[0] print(‘the shopping list is‘,shoppingList) print(‘my list is‘,myList,‘\n‘) print(‘Copy and then del‘) myList = shoppingList[:] del myList[0] print(‘the shopping list is‘,shoppingList) print(‘my list is‘,myList,‘\n‘) #原对象改变,被原对象赋值的变量也随着改变 #被赋值的变量改变,原对象也改变 #变量指向对象在内存中的地址,所以删除了地址上的内容,对大家都有影响 #如果采用切片方式取得值的话,就没有影响
2015/4/19 by Kerita
时间: 2024-10-10 06:21:53