Head_First_Python学习笔记(一)
来源:互联网 发布:sql group by 多列 编辑:程序博客网 时间:2024/05/22 14:28
列表操作:
>>> movies= ['the holy grail','the life of brain','the meaning of life’]>>> movies.insert(1,1975)>>> movies.insert(3,1979)>>> movies.append(1983)>>> movies['the holy grail', 1975, 'the life of brain', 1979, 'the meaning of life', 1983]
列表遍历:
>>> for movie in movies: print movie>>> count = 0>>> while count < len(movies):print movies[count]count++SyntaxError: invalid syntax(不支持++)>>> while count < len(movies):print movies[count]count = count + 1
在列表中遍历列表
默认不打印内列表
>>> movies = ['the holy grail', 1975, ['the life of brain', 1979,[ 'the meaning of life', 1983]]]>>> movies['the holy grail', 1975, ['the life of brain', 1979, ['the meaning of life', 1983]]]>>> for movie in movies:print moviethe holy grail1975['the life of brain', 1979, ['the meaning of life', 1983]]
递归版本
>>> def iter(movies):for movie in movies: if isinstance(movie,list): iter(movie) else: print movie>>> movies['the holy grail', 1975, ['the life of brain', 1979, ['the meaning of life', 1983]]]>>> iter(movies)the holy grail1975the life of brain1979the meaning of life1983
0 0
- Head_First_Python学习笔记(一)
- Head_First_Python学习笔记(二)
- Head_First_Python学习笔记(三)
- Head_First_Python学习笔记(四)
- head_first_python读书笔记
- 《Head_First_Python》4 持久存储
- 《Head_First_Python》 5推导数据
- XSLT学习笔记(一)
- Castor学习笔记(一)
- CSS学习笔记一
- 汇编学习笔记(一)
- ArcXML学习笔记(一)
- C#学习笔记(一)
- AIX学习笔记(一)
- PHP学习笔记(一)
- 串口学习笔记(一)
- JetSpeed学习笔记(一)
- symbian学习笔记一
- 过零丁洋
- 无题
- 常用的网络传输协议
- 解決Mac系統下"don't have permission to see its contents"問題
- 决策树的创建过程
- Head_First_Python学习笔记(一)
- 水果列表
- LeetCode Minimum Size Subarray Sum
- Libgdx 之贝塞尔曲线
- 一种离散数学中求传递闭包的算法实现
- android-BroadcastReceiver
- Libgdx 之资源加密保护
- 安卓-新浪微博评论
- s3c2440烧写第一步