笨办法学Python第39节

之前用的第三版的书,昨天发现内容不对,八块腹肌又给我下了第四版,这次的内容才对上。本节的代码如下:

 ten_things = "Apples Oranges Crows Telephone Light Sugar"

 print "Wait there's not 10 things in that list, let's fix that"

 stuff = ten_things.split(' ')

 more_stuff = ["Day","Night","Song", "Frisbee","Corn","Bananan","Girl","Boy"]

 while len(stuff)!=10:
next_one = more_stuff.pop()
print "Adding: ", next_one
stuff.append(next_one)
print "There's %d items now." % len(stuff) print "There we go: ",stuff print "Let's do some things with stuff." print stuff[1]
print stuff[-1]
print stuff.pop()
print ' '.join(stuff)
print '#'.join(stuff[3:5])

运行结果如下:

列表的操作中几点要注意:

stuff = ten_things.split(' '):以空格为标示分割字符串ten_things。
print stuff[1]:输出列表中序号是1的元素,在这里是Oranges。
print stuff[-1]:输出列表中最后一个元素。
print stuff.pop():输出列表中最后一个元素并在返回的时候删除。
print ' '.join(stuff):将列表中的元素用空格连接起来。
print '#'.join(stuff[3:5]):将序号为3的元素和序号为4的元素用#连接起来,注意不包括序号为5的元素。

最新文章

  1. Visual Studio 2015 前端开发工作流
  2. Web Api 简介
  3. 【转】PHP实现连贯操作
  4. (lleetcode)Merge Sorted Array
  5. HTML5自学笔记[ 1 ]新增标签
  6. 解决apache AH01630: client denied by server configuration错误
  7. android js调试
  8. C指针赋值
  9. java模拟浏览器包selenium整合了htmlunit,火狐浏览器,IE浏览器,opare浏览器驱
  10. C#中的深复制与浅复制
  11. location修改的时候报错解决办法
  12. C: strcpy & memcpy & scanf/printf format specifier.. escape characters..
  13. 10步完成Abp(.net core)+Vue的Demo?
  14. python 之走坑的道路
  15. 最短路 - floyd算法
  16. AI 可视化
  17. Linux网络基础-总
  18. 破解NET的四大神器(转)
  19. Information Retrieval
  20. i18n实现前端国际化(实例)

热门文章

  1. python之socket
  2. Spark学习(四) -- Spark作业提交
  3. item布局里有button之类的子控件时,会截获焦点
  4. 关于phpcms 万一忘记密码怎么破?
  5. CodeUI Test:创建第一个CodeUI Test
  6. Making my own Autonomous Robot in ROS / Gazebo, Day 1: Building the static model
  7. Django + mysql 快速搭建简单web投票系统
  8. public protect private. 草稿。
  9. overflow:hidden 影响布局的问题
  10. Libpci库的调用