标签:
PS:元祖和列表几乎一样
但是列表可以进行修改,元祖不能进行修改
1.元祖
name_tuple = ("cos", "sin", "tan")
# 索引
print (name_tuple[0])
# len
print (name_tuple[len(name_tuple)-1])
# 分片
print (name_tuple[0:1])
# for 循环
for n in name_tuple:
print (n)
# 删除不支持
del name_tuple[1] ps:元祖不能进行修改的
2.count 计算元素出现的个数
name_tuple = ("cos", "sin", "tan", "sin")
print (name_tuple.count("sin"))
3.index 获取指定元素的索引位置
name_tuple = ("cos", "sin", "tan")
print (name_tuple.index("sin"))
标签:
原文地址:http://www.cnblogs.com/keshanyong/p/5922073.html