Article From:

What is a list?

List is a collection of data, which can be placed in any data type, and can be easily added or deleted.

List function:


Create a list:

Method 1:L1= [] #Define an empty list
    L2 = ['ABC', ['123', '456']]    
Method 2: (No recommendation)List ()Name= list()

Query list:

    L2 = ['a', 'b', 'd','e']
    By index query, from 0, 0 is the subscript.The inverted query is L2= [-1]
    If the list is long, query the subscript of a number in the list.Using l2. index () methodIf the query list is used repeatedlyCount () methodL2.count ()

List slices:

    l2[0:3] Containing the head but not the tailL2[-5:-1] End-to-end sectionL2[:3] If you don't, start at the beginning and end at the end.L2[3:]
    L2[:] The default is allL2[:7:2]The back can be skipped slices, every two slices. (step length)

Add and amend:

    l2.append()Supplemental methodL2. insert (0,'zheng') insert, insert Zheng at position 0L2[2] = Modification of Subscript 2


l2.pop() The default pop is to delete the last one, or you can specify subscript deletion. POP deletion is possibleAcquired a= l2.pop(0)
    l2.remove()Delete by value, l2. remove ('zheng')
        remove()The method simply deletes the first value that appears in the list, and if it has more than one value, it can't.Delete, can only delete one, need to use a circular methoddel l2[0],Delete the value of the specified index, provided that the index location of the value is known


for i in l2:
        for Cycles have boundaries, whiles can have no boundaries


l2.sort()Permanent sorting of lists does not support int and STR sorting togetherSorting is based on the order of ASCLL code tableSort () is a positive sort. If you want to sort in reverse order, l2. sort (reverse)=True)
        Method.Sorted (l2) temporary sort,L2. Reverse () Prints the list backward, not backward, permanently backward. If you need to reverse back, execute this method twice

copy :

Copy methodL2= l1.copy()
    When L1 is modified, the value of L2 is not affected.If L2= l1:
        When the values in the L1 list are changed, the values in the L2 list are also changed.


Link of this Article: List function and some methods

Leave a Reply

Your email address will not be published. Required fields are marked *