1.元组(不能修改元组里的数据)
1.取值和索引
1.知道位置,确定内容
info_tuple =("zhangsan",18,1.75,"zhangsan")
print(info_tuple[0])
2.知道内容,确定位置,使用index方法
info_tuple =("zhangsan",18,1.75,"zhangsan")
print(info_tuple.index("zhangsan"))
2.元组的数据统计
1.统计计数:count
info_tuple =("zhangsan",18,1.75,"zhangsan")
print(info_tuple.count("zhangsan"))#运行结果:2
2.统计元组中包含元素的个数:len
info_tuple =("zhangsan",18,1.75,"zhangsan")
print(len(info_tuple))#运行结果:4
3.元组的遍历
使用迭代遍历元组
info_tuple =("zhangsan",18,1.75)
for my_info in info_tuple:
#使用格式字符串拼接 my_info这个变量不方便!
#因为元组中通常保存的数据类型是不同的!
print(my_info)