python中有三种内建的数据结构------列表,元组,字典
List:列表l是一组有序项目的数据结构,可增可减。表示方式:shoplist=['apple','banana','bango']
#!/usr/bin/python
#filename:using_list.py
shoplist=['apple','mango','carrot','banana']
print 'I have',len(shoplist),'items to purchase.'
print 'There items are:',
for item in shoplist:
print item,
print '\nI also have to buy rice.'
shoplist.append('rice')
print 'my shopping list is now', shoplist
print 'I will sort my list now', shoplist.sort()
print 'Sort shopping list is', shoplist
print 'The first item I will buy is',shoplist[0]
olditem=shoplist[0]
del shoplist[0]
print 'I brought the', olditem
print 'my shopping list is now ', shoplist
结果显示:其中函数sort()排序作用,del删除的作用,