Python Notes - basic data types - the list

List list 
        [A, B, C, D] created by the object class list, in parentheses, each of the intermediate element comma-separated 
        list of elements may be: a number, string '', the nested list, Boolean . . . . . all 
        may be modified

         - Select 
            [] [] of consecutive lookups 
            Test = [ ' A ' , ' ab & ' , ' ABC ' , ' ABCD ' ] 
            L = Test [0]         # returns the result 'A' 
            Li = Test [. 1] [ 1]     # returns the result 'B'
         
        - modify 
            Test = [ ' A ' , ' ab &' , ' ABC ' , ' ABCD ' ] 
            Test [ 2] = 120
             Print (Test)
             # returns the result [' A ',' ab & ', 120,' ABCD ']
 
        - Delete del 
            Test = [ ' A ' , ' ab & ' , ' ABC ' , ' ABCD ' ]
             del Test [2 ]
             Print (Test)
             # returns the result [' a ',' ab '
 ,'abcd']
        -Conversion
             - for string conversion list, directly List (), but can not directly convert a digital 
            Test = ' ABCD ' 
            new_test = List (Test)
             Print (new_test)
             # returns the result [ 'a', 'b' , 'c', ' D ']
 
            - the list into a string, a loop for a process, both numbers string 
            Test = [1,2, ' ab & ' ] 
            S = ' ' 
            for I in Test: 
                S = S + STR ( I)
             Print (S)
             # returns the result 12ab

            - If the string does not list all the digital 
            Test = [ ' 12 is ' , ' ab & ' ] 
            V = '' .join (Test)
             Print (V)
              # returns the result 12ab
 
        - DEF the append (Self, Object: _T) 
            in the original list adding the last element to be numbers, text, lists, etc. 
            Test = [ ' 12 is ' , ' ab & ' ] 
            test.append ( ' ABC ' )
             Print (Test)
            # Returns the result [ '12 is', 'ab &', 'ABC']
 
        - DEF Clear (Self) 
            All Clear list

         - DEF Copy (Self) 
            shallow copy 
            Test = [ ' 12 is ' , ' ab & ' ] 
            V = test.copy ( )
             Print (V)
             # returns the result [ '12 is', 'ab &']
 
        - DEF COUNT (Self, Object: _T) 
            number list an element appears calculated

         - DEF Extend (Self, Iterable: the Iterable [_T])  
            at the wish list of the last n elements is added, the inner loop, several additional possible numbers, text, lists, etc.
            parameter iterables 
            the Test = [ ' 12 is ' , ' ab & ' ] 
            test.extend ([ ' ABD ' ])
             Print (Test)
             # returns the result [ '12 is', 'ab &', 'ABD'] 
            test.extend ( ' ABC ' )
             Print (Test)
             # returns the result [ '12 is', 'ab &', 'ABD', 'a', 'B', 'C'] 
            @ Note: extend ([]), where [] do not leak

         - DEF index (Self, Object: _T, Start: int = ..., STOP: int = ...) 
            To find a value of the index position 
            test = [ ' 12 is ', ' Ab & ' ] 
            V = test.index ( ' ab & ' )
             Print (V)
             # return results. 1
 
        - DEF INSERT (Self, index: int, Object: _T) 
            inserted int index position is 
            Test = [ ' 12 is ' , ' ab & ' ] 
            test.insert ( 2, ' ABC ' )
             Print (Test)
             # returns the result [' 12 is', 'ab &', 'ABC']
 
        - DEFPOP (Self, index: int = ...) 
            remove a value, and obtains deleted values, the default is the last 
            Test = [ ' 12 is ' , ' ab & ' ] 
            V = test.pop (. 1 )
             Print (Test)
             Print (V)
             # returns the result    
            # # [ '12 is'] 
            # # ab &
 
        - DEF remove (Self, Object: _T) 
            delete a value, if repeated, a default deletion left first

         - DEF Reverse (Self) 
            list the entire sequence order reversal 
            Test = [ ' 12 is ', ' Ab & ' ] 
            test.reverse () 
            Print (test)
             # returns the result [ 'ab &', '12 is']
 
        - DEF Sort (Self, Key = none, = Reverse to false) 
            a digital sequence sorted by size 
            test = [11,22,44,33,11 ] 
            test.sort () 
            Print (Test)
             # returns the result [. 11,. 11, 22 is, 33 is, 44 is] 
            test.sort (Reverse = True) 
            @ Note: Reverse = True True The first character must be capitalized, Python fixed format
             Print (Test)
             # returns the result [44, 33, 22, 11, 11]

 

Guess you like

Origin www.cnblogs.com/joyceluyun/p/12488881.html