Difference in python arrays, lists, tuples, definition, function

Accurate, it is not the type of array in python, python, replaced by lists and tuples. List of tuples than easy to use, because once the tuple would not be able to modify the definition. The list not only the same array and accessed by index, there are a bunch of functions.

List:

    (1) add

        To the end of the list of additional elements a: a.append (i)

                                                                      

         To a list anywhere additional elements: a.insert (i, elem), where i represents the index position, elem presentation elements.

                                                                       

   (2) Delete:

        Removes the specified position of the elements: del a [i]

 

 

 

                                                             

 

 

 

        Delete elements in the list: a.remove (elem)

                                                             

        Delete the tail of the list of elements (a bit like a stack pop ha ha): a.pop ()

                                                              

 

     (3) Development:

        The list is appended to a tail of b: a.extend (b)

                  

 

      Number (4) statistical elements appear: a.count (elem)

                  

 

       (5) Sort: list.sort (self, key = None, reverse = False) where key is only useful if the element string, in accordance with a keyword indicating a sort (e.g., string length)

        digital:

          In ascending order (the default in ascending order): a.sort ()

                  

 

          If you want to follow in descending order, was: a.sort (reverse = True)

        String:

          According to the size of the ASCII codes in ascending Sort:

                  

 

           Descending order: a.sort (reverse = True)

                     

 

          Be sorted in descending order according to the length of the string: a.sort (key = len, reverse = True)

                   

 

      (6) Flip:

          Flip the list of elements: a.reverse ()

                  

 

      (7) returns a list of length: len (a)

      (8) Get the subscript elements: list.index (elem)

 

Tuple:

    Tuple has two actions:

      (1) returns the number of elements in the tuple: tuple.count (elem)

 

                    

 

      (2) find elements of position: tuple.index (elem, start)

                 

 

 

Summary: (1) compared to lists and tuples, the function can be called directly more can be changed, but a tuple by definition can not be changed, so the most important list.

   (2) If you have to use an array, we have python with python numpy library may be implemented in an array to define:

                  

 

 

 

 

 

      

 

 

 

                  

        

      

 

        

 

Guess you like

Origin www.cnblogs.com/Ycc-LearningRate/p/11517791.html