shoplist = ['apple', 'mango', 'carrot', 'banana'] #定义一个列表print 'I have', len(shoplist),'items to purchase' #计算列表长度print 'These items are:', #遍历列表for item in shoplist: print item, print '\nI also to buy rice'shoplist.append('rice') #列表当中添加itemprint 'My shopping list is now',shoplistprint 'I will sort my list now'shoplist.sort() #列表进行排序print 'Sorted shopping list is ',shoplistprint 'The first item I will buy is',shoplist[0] #访问单个列表元素olditem = shoplist[0]del shoplist[0] #删除列表元素print 'I bought the',olditemprint 'My shopping list is now',shoplist