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

  • 相关阅读:
    sharpen和filter2D
    Changing the contrast and brightness of an image!(opencv对比度和亮度调节)
    人脸表情识别
    Pycharm下载和安装
    Anaconda下载与安装
    图像人脸检测+人眼检测 (opencv + c++)
    cv2.VideoWriter()指定写入视频帧编码格式
    python_openCV例程遇到error: (-215) !empty() in function cv::CascadeClassifier::detectMultiScale的简单解决方法
    图像处理库 Pillow与PIL
    IDE bulid构建隐藏了什么(预处理->编译->汇编->链接)
  • 原文地址:https://www.cnblogs.com/xiaohouzai/p/7639336.html
Copyright © 2011-2022 走看看