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]
    >>>

  • 相关阅读:
    TCP三次握手和四次挥手详解
    Core Bluetooth Programming Guide
    iBeacon
    Xcode6:The file couldn’t be opened because you don’t have permission to view it
    关于IOS的蓝牙(转)
    iPad accessory communication through UART
    关于蓝牙设备与ios连接后,自动打开一个app
    Protocol
    闪屏效果
    修改avd路径
  • 原文地址:https://www.cnblogs.com/xiaohouzai/p/7639336.html
Copyright © 2011-2022 走看看