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

  • 相关阅读:
    js异步加载服务端数据
    日期操作
    《jQuery实战》第2章 创建元素和包装集
    访问共享目录电脑盘符
    《jQuery实战》第4章 事件
    《jQuery实战》第3章 用JQuery让页面生动起来
    div + CSS 学习笔记
    WinJS Promise设置超时,可用于设置网络请求超时
    WinJS Base64编码和解码 metro
    Javascript Base64编码和解码
  • 原文地址:https://www.cnblogs.com/xiaohouzai/p/7639336.html
Copyright © 2020-2023  润新知