重拾python 三十二
来源:互联网 发布:安庆市民心声网络问政 编辑:程序博客网 时间:2024/04/29 11:54
开始学习循环语句,关键字for;学习一个基本的数据结构列表(list),用[]表示,上代码ex32.py:
#!/usr/bin/python# -*- coding: utf-8 -*-numbers = [1, 22, 333, 4444, 55555]fruits = ['apples', 'oranges', 'pears', 'apricots']unknown = [5, 'tom', [2,'funny'], 'jerry', 3, 'wang']for number in numbers: print "This is number %d" % numberfor fruit in fruits: print "A fruit of type: %s" % fruitfor i in unknown: print "I got %r" % ielements = []for i in range(0, 6): print "Adding %d to the list." % i elements.append(i)for i in elements: print "Element was: %d" % i
运行,看到:
This is number 1
This is number 22
This is number 333
This is number 4444
This is number 55555
A fruit of type: apples
A fruit of type: oranges
A fruit of type: pears
A fruit of type: apricots
I got 5
I got ‘tom’
I got [2, ‘funny’]
I got ‘jerry’
I got 3
I got ‘wang’
Adding 0 to the list.
Adding 1 to the list.
Adding 2 to the list.
Adding 3 to the list.
Adding 4 to the list.
Adding 5 to the list.
Element was: 0
Element was: 1
Element was: 2
Element was: 3
Element was: 4
Element was: 5
可以看到,列表的元素可以是列表哦
0 0
- 重拾python 三十二
- python入门(三十二):类的特殊成员
- 重拾Python 一
- 重拾Python 二
- 重拾Python 三
- 重拾Python 四
- 重拾Python 五
- 重拾Python 六
- 重拾Python 七
- 重拾Python 八
- 重拾Python 九
- 重拾Python 十
- 重拾Python 十一
- 重拾Python 十二
- 重拾Python 十七
- 重拾Python 十八
- 重拾python 十九
- 重拾python 三十
- 面向对象(数组代码分析)
- 24Windows消息队列
- MFC中将所画图像保存到图像文件
- 14 并发编程
- Uva816 Abbott's Revenge【bfs】【例题6-14】
- 重拾python 三十二
- HTTPS①通信流程
- 神级以下必读! ~程序猿学习资料集 02
- 14.1 什么是线程
- 25FatMouse的语言
- Eclipse的常用快捷键
- io——cpp——格式控制
- YOLOv2训练自己的数据集(VOC格式)
- Android的Log等级