zoukankan      html  css  js  c++  java
  • Python第二天-元组的基本使用方法

    由于精力充沛,再来一篇博客压压惊!

      元组(tuple)的用法和list基本一样,但是,元组不能删除修改,这是元组最关键的特性

    1.定义元组

    arr=("123","456","789")

    2.获取第一个元素

    arr=("123","456","789")
    print(arr[0]);

    结果:123

    3.遍历(迭代)

    arr=("123","456","789")
    for a in arr:
        print(a);

    结果:123
       456
       789

    4.count()方法--统计指定元素在元组中出现的次数

    arr=("123","456","123")
    count=arr.count("123")
    print(count);

    结果:2

    5.index():统计字符串在元组中第一次出现的位置

    arr=("123","456","123")
    count=arr.index("123")
    print(count);

    结果:0

    6.测试删除元组中的数据:

    arr=("123","456","123")
    del arr[0:1]
    print(arr);

    结果:TypeError: 'tuple' object does not support item deletion

    ---------------------------------结束----------------------------------------

    还有精力?再来!!!

  • 相关阅读:
    poj2752Seek the Name, Seek the Fame【kmp next数组应用】
    poj1961Period【kmp next数组】
    poj2406(kmp next数组)
    KMP原理
    0529
    0428
    2045年4月25日
    0421
    黄金连分数【大数】
    学习linux内核时常碰到的汇编指令(1)
  • 原文地址:https://www.cnblogs.com/dingjm01/p/7853837.html
Copyright © 2011-2022 走看看