元组的常用操作

在 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))

 

相关文章:

  • 2021-09-07
  • 2022-12-23
  • 2021-06-16
  • 2022-02-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-06
  • 2021-10-21
猜你喜欢
  • 2021-12-30
  • 2022-12-23
  • 2021-12-08
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
相关资源
相似解决方案