zoukankan      html  css  js  c++  java
  • python列表三

      

    >>> list1 = [123]
    >>> list2 =[234]
    >>> list1 > list2
    False
    >>> list1 = [123,456]
    >>> list2 = [456,123]
    >>> list3 = [234,123]
    >>> (list1<list2)and(list1 == list3)
    False
    >>> list3= [123,456]
    >>> (list1<list2)and(list1 == list3)
    True
    >>> list4 = list1 + list2
    >>> list4
    [123, 456, 456, 123]
    >>>

    >>> list3
    [123, 456]
    >>> list3* 3
    [123, 456, 123, 456, 123, 456]
    >>> list3 *= 3
    >>> list3
    [123, 456, 123, 456, 123, 456]
    >>>

    >>> list3
    [123, 456, 123, 456, 123, 456]
    >>> 123 in list3
    True
    >>> "li" not in list3
    True
    >>>

    >>> list5 = [123,456,["小虎","小胡","小尹"]]
    >>> "小虎"in list5
    False

    >>> "小虎"in list5[2]
    True
    >>>


    list[2][1]
    TypeError: 'type' object is not subscriptable
    >>> list5[2][1]
    '小胡'
    >>>

    count计算出现的次数

    >>> list3.count(123)
    3
    >>> list3
    [123, 456, 123, 456, 123, 456]
    >>> list3 *= 5
    >>> list3
    [123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456]
    >>> list3.count(123)
    15
    >>>

    index出现元素的值的下标

    >>> list3
    [123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456]
    >>> list3.index(123)
    0
    >>> list3.index(123,3,6)
    4
    >>>

    reserve(重要)反转

    >>> list3.reverse()
    >>> list3
    [456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123, 456, 123]
    >>>

    sort(最重要)排序,默认归并排序

    >>> list6 = [0,5,1,2,4,9,6,7,3]
    >>> list6.sort()
    >>> list6
    [0, 1, 2, 3, 4, 5, 6, 7, 9]
    >>> list6.sort(reverse=True)
    >>> list6
    [9, 7, 6, 5, 4, 3, 2, 1, 0]
    >>>

    注意 : list7 = list6[:] ,使用分片来拷贝列表,原来列表排序对拷贝后的列表没有影响,如果使用=来复制列表,则原来列表排序后对复制后的列表有影响

    >>> list6
    [9, 7, 6, 5, 4, 3, 2, 1, 0]
    >>> list7 = list6[:]
    >>> list7
    [9, 7, 6, 5, 4, 3, 2, 1, 0]
    >>> list8 = list6
    >>> list8
    [9, 7, 6, 5, 4, 3, 2, 1, 0]
    >>> list6.sort()
    >>> list6
    [0, 1, 2, 3, 4, 5, 6, 7, 9]
    >>> list7
    [9, 7, 6, 5, 4, 3, 2, 1, 0]
    >>> list8
    [0, 1, 2, 3, 4, 5, 6, 7, 9]
    >>>

  • 相关阅读:
    发送指令
    WIN32得到HWND
    查找摄像头
    WindowImplBase::OnSysCommand-------duilib在最大化和还原间切换
    CImage将图片转为指定像素大小
    聚集索引和非聚集索引(整理)
    数据库SQL优化大总结之 百万级数据库优化方案
    架构师之路(39)---IoC框架
    .NET Reflector反编译的方法
    PowerDesigner之PDM(物理概念模型)
  • 原文地址:https://www.cnblogs.com/xiaohouzai/p/7639336.html
Copyright © 2011-2022 走看看