标签:删除 可重复 根据 类型 ESS code col 格式 进阶
tp1 = ("name","age",23,"height","address","job") tp1 = (name,job) = ["chen","IT"] tp1 = () tp1 = ("python",) print(tp1,type(tp1))
由tuple不可变的特点可知,元组中的元素是无法进行单独更改,增加和删除的。
获取元组中的元素(切片)
tp2 = ("name","age",23,"height","address","job") print(tp2[0],tp2[3]) #根据索引位置获取元组中的元素
print(tp2[1:5:1]) #切片得到索引内的元素
index和count函数
tp2 = ("name","age",23,"height","address","job") print(tp2.index("age")) #通过元素名找到该元素所在位置索引 print(tp2.count("age")) #查找该名称元素的在列表中个数(有多个相同元素的时候)
合并两个元组“+”,得到一个新的元组
tp3 = ("name","age",23,"height","address","job") tp4 = ("name",(23,"python")) tp5 = tp3 + tp4 print(tp5)
元组的删除,只能借助与del函数,
tp6 = ("name","age",23,"height","address","job") del tp6
print(tp6) #tp6被回收,无地址,报错
小白的python进阶历程------07.元组(tuple)
标签:删除 可重复 根据 类型 ESS code col 格式 进阶
原文地址:https://www.cnblogs.com/chen-sang-python/p/9677632.html