Python(元组)
来源:互联网 发布:on淘宝旗舰店 编辑:程序博客网 时间:2024/05/17 23:34
元组跟列表相似,不同点是元组里的元素不能更改。
元组的形式
用小括号 tup1 = ('apple', 'iphone', 2016, 2017)
或者 tup3 = 'x', 'y', 'z'
空元组 tup=()
只有一个元素的元组,元素后要加“,” tup = (123,)
元组的连接组合
tup4=tup1+tup2
元组是不允许删除其中元素值的,但能通过del方法来删除整个元组,就像这样:
del tup4print tup4
显示
NameError: name ‘tup4’ is not defined
重复元素如何表示(列表和元组都适用)
tup4=(100,)*5
获取元组长度
len(tup4)
遍历(列表和元组都适用)
tup2=('cat','dog',100,200)for x in tup2: print x
自己的小练习
for循环和元组结合
tup2=('cat','dog',100,200)for a in tup2: if (a>90): print a else: continue
阅读全文
0 0
- Python(元组)
- Python数据类型(三):列表元组
- 序列之三 元组(Python)
- Python笔记(三) 元组、文件
- python列和元组(一)
- python列和元组(二)
- Python 元组(tuple)操作
- python入门之(元组、文件)
- Python数据类型-序列(元组)
- Python--列表和元组(1)
- python(二)列表,元组,循环
- python 学习(十四)之元组
- python 命名元组(namedtuple)
- Python (二)列表、元组
- python学习笔记5(元组)
- python数据类型-元组(tuple)
- python基础篇--Tuple(元组)
- 4 Python之tuple(元组)
- python logging模块
- 遍历多个List时,如何一层一层的遍历,然后一层一层的输出!
- Kotlin项目练习记录 续
- 「前端 · 面试」记录一些有意思的题目(一)
- c++经验总结(3):link错误,无法打开XXX.lib或者xxx.obj
- Python(元组)
- Redhat6.6安装Ambari2.0.1
- loj #100. 矩阵乘法
- PAT_1079. Total Sales of Supply Chain
- unity如何获取安卓手机的时间电量网络信息
- 浅析c与c++中struct的区别
- mysql 创建能级联删除的表
- jQuery基础
- x264_param_t结构体解释,设置及对应函数位置