1. delete an element
Names = ['Thy ', 'jj', 'God', 'Dog']
Del Names [1] ---> ['Thy ', 'God', 'Dog']
2. Clip assignment
Names [1:] = List ('Thy ') ---> ['Thy', 't', 'h', 'y']
Names [2: 2] = [] ---> ['Thy ', 't', 'y']
However, you must note that the right value of the clip can only be list.
3. append added to the end
Names. append (3) ---> ['Thy ', 't', 'h', 'y', 3]
4. Count statistics on specified elements
['To', 'be', 'or', 'not ', 'to', 'be']. Count ('to') ---> 2
5. Add a sequence to the end of extend.
Gender = ['F', 'M']
Names. Extend (gender) ---> ['Thy ', 't', 'h', 'y', 3, 'M', 'F']
Note that although names + gender has the same results, it is only a cache result, unless names = names + gender
6. Index returns the first subscript that meets the condition.
['To', 'be', 'or', 'not ', 'to', 'be']. Index ('to') ---> 0
['To', 'be', 'or', 'not ', 'to', 'be']. Index ('to', 1) ---> 4
7. insert an object at a specified position
Names. insert (3, gender) ---> ['Thy ', 't', 'h', ['M', 'F'], 'y', 3, 'M', 'F']
Note that gender is inserted as a whole list object.
8. Pop can simulate stack operations (starting from the end)
Names. pop () ---> 'F' # (at the same time, the names value is changed to ['Thy ', 't', 'h', ['M', 'F'], 'y', 3, 'M'])
Names. pop (3) ---> ['M', 'F'] # (at the same time, the names value is changed to ['Thy ', 't', 'h', 'y ', 3, 'M'])
9. Remove Delete(But unlike pop, it does not return values)
10. Reverse reverse list
11. Sort
The basic type is simple. The default value is ascending (sort (reverse = true) followed by descending)
X = [,]
X. Sort () ---> [,] # note that sort () does not return values.
Names. Sort () ---> [3, 'M', 'h', 't', 'Thy ', 'y']
Y = x. Sort () does not assign values to Y, because sort () does not return values. You can use y = sorted (x) instead)
For complex types, you need to specify the CMP comparison function (this is included in the function chapter)
You can also specify the key to sort
X = ['dvark', 'abalone', 'acme ', 'add', 'aerate']
X. sort (Key = Len) ---> ['add', 'acme', 'dvark', 'aerate', 'abalone']
X. sort () ---> ['abalone', 'acme', 'add', 'aerate', 'dvark']