Learn Python the Hard Way(“笨办法”学python) 第四版 例39笔记
来源:互联网 发布:java泛型坑 编辑:程序博客网 时间:2024/06/05 03:07
39 列表的操作
python菜鸟最近在学Learn Python the Hard Way这本书,将笔记分享出来和大家一起学习!
小点解析(来自脚本之家和陶子自己的理解):
**1.**str.split(str=”“,num=string.count(str))
str——分隔符,默认为所有的空字符,包括空格,换行(\n), 制表符(\t)等,上面的例子中用的是空格
num——分割次数
**2.**list.pop(obj=list[])
list.pop()默认移除最后一个元素并返回该元素值
**3.**str.join(sequence)
注意理解join(str,sequence)
将sequence中的元素以str连接
ten_things="Apple Oranges Crows Telephone Light Sugar"print("Wait there's not 10 things in that list,lest's fix that.")stuff=ten_things.split(' ')#此处指定分隔符为空格,经过分割之后,len(stuff)等于6more_stuff['Day','Night','Song','Firsbee','Corn','Banana','Girl','Boy']while len(stuff)!=10: next_one=more_stuff.pop() #指的是删除more_stuff最后 一个元素并将该元素返回,赋值给else 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中的3和4位置上元素以#连接
阅读全文
0 0
- Learn Python the Hard Way(“笨办法”学python) 第四版 例39笔记
- 笨办法学 Python (Learn Python The Hard Way)
- learn python the hard way(笨办法学python) 练习39
- learn python the hard way(笨办法学python) 附录 个人整理
- learn python the hard way(笨办法学python) 习题22
- learn python the hard way(笨办法学python) 练习32 附加练习
- learn python the hard way(笨办法学python) 练习38 附加练习
- learn python the hard way(笨办法学python) 练习40 类的用法
- learn python the hard way(笨办法学python) 练习10
- learn python the hard way(笨办法学python) 练习46
- learn python the hard way(笨办法学python) 练习50
- 笨办法学 Python (Learn Python The Hard Way)——003
- 第一本计算机书—笨办法学 Python (Learn Python The Hard Way)
- Learn Python The Hard Way-笨方法学Python
- 跟着《Learn Python The Hard Way》学Python(一)
- 跟着《Learn Python The Hard Way》学Python(二)
- 学《learn python the hard way》(3)
- 学《learn python the hard way》(1)
- POJ 2406 Power Strings (KMP) kmp循环节
- 阿里云centos环境之mysql安装<二>
- 记录自学Java的第一篇
- ACM-10月19日周四周中训练心得
- Python3中dict.keys()转换成list类型
- Learn Python the Hard Way(“笨办法”学python) 第四版 例39笔记
- delphi跳出循环体
- GitPush避免重复输入用户名和密码
- 神经网络的层参数维度(14)---《深度学习》
- Mybatis实现对DB增删改查 (前)学习工具
- 线程池
- 关于Java实现连接服务器获取更新
- java-容器
- cf 870 B