12.Python
来源:互联网 发布:全球房价排名 知乎 编辑:程序博客网 时间:2024/06/08 12:32
Tuple
用小括号、或者无括号来表述,是一连串有顺序的数字。
a_tuple = (12, 3, 5, 15, 6)
another_tuple = 12, 3, 5, 15 , 6
List
以中括号来命名:
a_list = [12, 3, 67, 7, 82]
两者对比
他们的元素可以一个一个地被迭代、输出、运用、定位取值:
for content in a_list:
print(content)
"""
12
3
67
7
82
"""
for content_tuple in a_tuple:
print(content_tuple)
"""
12
3
5
15
6
"""
下一个例子,依次输出a_tuple和a_list中的各个元素:
for index in range(len(a_list)):
print("index = ", index, ", number in list = ", a_list[index])
"""
index = 0 , number in list = 12
index = 1 , number in list = 3
index = 2 , number in list = 67
index = 3 , number in list = 7
index = 4 , number in list = 82
"""
for index in range(len(a_tuple)):
print("index = ", index, ", number in tuple = ", a_tuple[index])
"""
index = 0 , number in tuple = 12
index = 1 , number in tuple = 3
index = 2 , number in tuple = 5
index = 3 , number in tuple = 15
index = 4 , number in tuple = 6
"""
- 12.Python
- Python
- Python
- Python
- python
- Python
- PYTHON
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- python
- Java多线程编程:Callable、Future和FutureTask浅析
- SQL-已存在数据的表主键设置递增
- 第十二周 【项目5
- DevExpress XtraTabControl 加载Form,不重复显示,自动定位打开页面
- webstorm破解方法(亲测可用)
- 12.Python
- zookeeper笔记(一)
- 2018 年趋势:AI 和物联网的未来将会如何?
- 第十周项目一 二叉树构造算法的验证---由顺序存储结构转为二叉链存储结构(4)
- ROS创建一个services
- 阿里云负载均衡器(SLB)的配置方法
- div背景色渐变
- httpclient连接池释放异常和多余资源
- 使用转换mnist数据库保存为bmp图片