Python学习06——列表的操作(2)
2024-10-20 15:49:11
笨办法学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的元素。
最新文章
- Visual Studio 2015 前端开发工作流
- Web Api 简介
- 【转】PHP实现连贯操作
- (lleetcode)Merge Sorted Array
- HTML5自学笔记[ 1 ]新增标签
- 解决apache AH01630: client denied by server configuration错误
- android js调试
- C指针赋值
- java模拟浏览器包selenium整合了htmlunit,火狐浏览器,IE浏览器,opare浏览器驱
- C#中的深复制与浅复制
- location修改的时候报错解决办法
- C: strcpy &; memcpy &; scanf/printf format specifier.. escape characters..
- 10步完成Abp(.net core)+Vue的Demo?
- python 之走坑的道路
- 最短路 - floyd算法
- AI 可视化
- Linux网络基础-总
- 破解NET的四大神器(转)
- Information Retrieval
- i18n实现前端国际化(实例)
热门文章
- python之socket
- Spark学习(四) -- Spark作业提交
- item布局里有button之类的子控件时,会截获焦点
- 关于phpcms 万一忘记密码怎么破?
- CodeUI Test:创建第一个CodeUI Test
- Making my own Autonomous Robot in ROS / Gazebo, Day 1: Building the static model
- Django + mysql 快速搭建简单web投票系统
- public protect private. 草稿。
- overflow:hidden 影响布局的问题
- Libpci库的调用