• 列表list


    列表:
    
    Python序列(Sequence)
    
      def __init__(self, seq=()): # known special case of list.__init__
            """
            list() -> new empty list
            list(iterable) -> new list initialized from iterable's items
            # (copied from class doc)
            """
            pass
    
    例:
      #li = list([1,2,3])
      li = list((1,2,3))
      print(li)
    尾部添加一个元素:
    def append(self, p_object): # real signature unknown; restored from __doc__ """ L.append(object) -> None -- append object to end """ pass

    把列表清空: def clear(self): # real signature unknown; restored from __doc__ """ L.clear() -> None -- remove all items from L """ pass

    拷贝(浅拷贝): def copy(self): # real signature unknown; restored from __doc__ """ L.copy() -> list -- a shallow copy of L """ return []
    判断某个元素出现的次数:
    def count(self, value): # real signature unknown; restored from __doc__ """ L.count(value) -> integer -- return number of occurrences of value """ return 0
    合并两个列表(对原来列表的一个扩展):
    def extend(self, iterable): # real signature unknown; restored from __doc__ """ L.extend(iterable) -> None -- extend list by appending elements from the iterable """ pass
    例:
      li = list([1,2,3])   print(li)   #li.extend([11,22]) 列表   li.extend((11,22))#元组   print(li)
    得:
      
    [1, 2, 3]

      [1, 2, 3, 11, 22]
    获取下标:
    def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__ """ L.index(value, [start, [stop]]) -> integer -- return first index of value. Raises ValueError if the value is not present. """ return 0
    指定下标添加:
    def insert(self, index, p_object): # real signature unknown; restored from __doc__ """ L.insert(index, object) -- insert object before index """ pass   
    li.insert(0,"xiaolong")

    删除并获取这个值:

        def pop(self, index=None): # real signature unknown; restored from __doc__
            """
            L.pop([index]) -> item -- remove and return item at index (default last).
            Raises IndexError if list is empty or index is out of range.
            """
            pass
    例:
    li = list([1,2,3]) print(li) #li.extend([11,22]) 列表 #li.extend((11,22))#元组 li.insert(0,"xiaolong") ret = li.pop(0) print(li) print(ret) 得: [1, 2, 3] [1, 2, 3] xiaolong

    删除(第一个值):
        def remove(self, value): # real signature unknown; restored from __doc__
            """
            L.remove(value) -> None -- remove first occurrence of value.
            Raises ValueError if the value is not present.
            """
            pass
    例:
      li = [11,11,2,22,2]   print(li)   li.remove(11)   print(li)

    得:

        [11, 11, 2, 22, 2]
        [11, 2, 22, 2]

    反转:
        def reverse(self): # real signature unknown; restored from __doc__
            """ L.reverse() -- reverse *IN PLACE* """
            pass
    例:
    li = [11,22,33,44,55] print(li) li.reverse() print(li)
    得:

      [11, 22, 33, 44, 55]
      [55, 44, 33, 22, 11]

    排序:
        def sort(self, key=None, reverse=False): # real signature unknown; restored from __doc__
            """ L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE* """
            pass
  • 相关阅读:
    python全栈开发_day17_时间,系统模板和序列化
    python全栈开发_day15_函数回调和模块
    python全栈开发_day16_包
    pygame学习_part1_pygame写程序前的准备工作
    python全栈开发_day15_模块学习
    不确定性推理复习
    hibernate级联关系
    hibernate双向一对多关联关系
    实践:hibernate-one2many(单向)
    我的学习(修改完善)
  • 原文地址:https://www.cnblogs.com/mrzuo/p/7083656.html
Copyright © 2020-2023  润新知