小甲鱼-013元组tuple:上了枷锁的列表
1.创建和访问一个元组
1.1创建元组
元组的标志性符号是 ,
tuple1 = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
#定义单个元素的元组,要加 ,
tuple2 = (1,)
tuple3 = 1, 2, 3
tuple4 = (1)
#定义一个空元组
tuple5 = ()
print(type(tuple1),type(tuple2),type(tuple3),type(tuple4),type(tuple5))
![](https://img2018.cnblogs.com/blog/1418970/201901/1418970-20190101203221138-462084378.png)
![](https://img2018.cnblogs.com/blog/1418970/201901/1418970-20190101201313841-597165387.png)
![](https://img2018.cnblogs.com/blog/1418970/201901/1418970-20190101201638617-1564055149.png)
# * 重复操作符复制元组
tuple1 = (8,)
print(tuple1 * 8)
![](https://img2018.cnblogs.com/blog/1418970/201901/1418970-20190101203658241-2069288279.png)
3.更新和删除一个元组
tuple1 = ('大娃', '二娃', '三娃', '四娃', '五娃', '六娃', '七娃')
#更新元组,实际是组装生成一个新元组,并将标签指向新元组。原来的旧元组在没有标签指向它的时候会被python的垃圾回收机制清理掉
tuple1 = tuple1[:2] + ('爷爷',) + tuple1[2:]
print(tuple1)
#删除元组
del tuple1
![](https://img2018.cnblogs.com/blog/1418970/201901/1418970-20190101210215537-293193435.png)