python_元组_基本操作

元组的常用操作

在 python 中,提供了2个操作元组的 函数

info.count  info.index

info.count 获取某一个数据在元组中出现的次数

info.index 获取某一个数据在元组中对应的索引下标

1 info_tuple = ("zhangsan",18,1.75,1.75)
2 
3 #1.取值和取索引
4 print(info_tuple[0])
5 print(info_tuple.index(18))
6 #2.统计计数
7 print(info_tuple.count(1.75))
8 #3.统计元组中包含元素的个数
9 print(len(info_tuple))

猜你喜欢

转载自www.cnblogs.com/shao-null/p/9269350.html
今日推荐