《笨办法学Python》 第39课手记
来源:互联网 发布:网络歌曲 喜欢你喜欢你 编辑:程序博客网 时间:2024/06/10 21:48
《笨办法学Python》 第39课手记
本节课讲列表的操作,用来做练习的代码中出现了之前用到过的几个函数,是一节复习课。你需要记住它们。
原代码如下:
ten_things = "Apples Orange 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", "Banana", "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: ", stuffprint "Let's do some things with stuff"print stuff[1]print stuff[-1] # whoa!! fancyprint stuff.pop()print ' '.join(stuff) # what? cool!print '#'.join(stuff[3:5]) # super stellar!
结果如下:
本节课涉及的知识:
1.stuff.split(’ ‘),以空格为标志分割字符串,默认全部分割,可以在括号里”后面指定参数以使解释器按规定次数分割。
2.stuff.append(next_one),向列表stuff中增添元素next_one,执行方式作者在文中有介绍。
3.print ‘#’.join(stuff[3:5]) ,用#将stuff中的第3个元素和第4个元素连接起来,[3:5]这个参数给出了要连接的元素在列表中的位置,注意不包括第5个元素。
0 0
- 《笨办法学Python》 第39课手记
- 《笨办法学Python》 第0课手记
- 《笨办法学Python》 第1课手记
- 《笨办法学Python》 第2课手记
- 《笨办法学Python》 第3课手记
- 《笨办法学Python》 第4课手记
- 《笨办法学Python》 第5课手记
- 《笨办法学Python》 第6课手记
- 《笨办法学Python》 第7课手记
- 《笨办法学Python》 第8课手记
- 《笨办法学Python》 第9课手记
- 《笨办法学Python》 第10课手记
- 《笨办法学Python》 第11课手记
- 《笨办法学Python》 第12课手记
- 《笨办法学Python》 第13课手记
- 《笨办法学python》 第14课手记
- 《笨办法学Python》 第15课手记
- 《笨办法学Python》 第16课手记
- 商业级别Fortify白盒神器介绍与使用分析
- Java——List的实现类
- LeetCode 169. Majority Element
- 面向切面编程(AOP)的理解
- TransformerFactory(示例,出错代码)
- 《笨办法学Python》 第39课手记
- Android Studio 小技巧合集
- IOS开发之常见bug
- Redis学习到实战(一)基础与入门
- Android侧滑菜单(最简)
- Filter过滤器的强大功能
- 算法学习--图论
- AOP的基本概念理解
- CF544C&51nod1086【限定个数的完全背包】