Chinaunix首页 | 论坛 | 博客
  • 博客访问: 45214
  • 博文数量: 44
  • 博客积分: 50
  • 博客等级: 民兵
  • 技术积分: 240
  • 用 户 组: 普通用户
  • 注册时间: 2011-12-16 06:05
文章分类

全部博文(44)

文章存档

2012年(32)

2011年(12)

我的朋友

分类: Python/Ruby

2011-12-16 22:46:46

  1. # List
  2. #create a list
  3. shoplst = ["apple", "mango", "carrot","banana"]

  4. #traverse items
  5. print "i hava", len(shoplst), "items to purchase."

  6. for item in shoplst:
  7.   print(item)

  8. #add items
  9. print "i also hava to buy *rice*."
  10. shoplst.append("rice")
  11. print "my shopping list is now", shoplst

  12. #sort the list
  13. shoplst.sort()
  14. print shoplst

  15. #search the item
  16. print shoplst[1]

  17. #delete items
  18. olditem = shoplst[0]
  19. del shoplst[0]
  20. print olditem
  21. print shoplist
阅读(93) | 评论(0) | 转发(0) |
0

上一篇:二叉树的一个简单应用

下一篇:20111217

给主人留下些什么吧!~~