- 博客访问: 45214
- 博文数量: 44
- 博客积分: 50
- 博客等级: 民兵
- 技术积分: 240
- 用 户 组: 普通用户
- 注册时间: 2011-12-16 06:05
分类: Python/Ruby
2011-12-16 22:46:46
- # List
-
#create a list
-
shoplst = ["apple", "mango", "carrot","banana"]
-
-
#traverse items
-
print "i hava", len(shoplst), "items to purchase."
-
-
for item in shoplst:
-
print(item)
-
-
#add items
-
print "i also hava to buy *rice*."
-
shoplst.append("rice")
-
print "my shopping list is now", shoplst
-
-
#sort the list
-
shoplst.sort()
-
print shoplst
-
-
#search the item
-
print shoplst[1]
-
-
#delete items
-
olditem = shoplst[0]
-
del shoplst[0]
-
print olditem
-
print shoplist