# -*- coding: cp936 -*- #list example # 创建list shoplist = ['apple', 'mango', 'carrot'] # 遍历list for item in shoplist: print item # 子集 print shoplist[:2] # 打印从[0,2)的元素 # 修改元素 shoplist[0] = 'apples' # 添加元素 shoplist.append('banana') # 将新元素'banana'插入到链表尾部 shoplist.insert(1, 'rice') # 在shoplist[1]之前插入新元素'rice' # 排序 shoplist.sort() # 删除元素1 del shoplist[1] #删除元素2 shoplist.remove('rice')