14-python base - a list of common operations

A list of common operations:

  • The next Ubuntu ipython3 define a list lst = []
  • Enter lst.TAB
  • List of methods that can be used ipython will be prompted.

 

1. Increase list data

No. Keyword / function / method Explanation
1 List .insert (index data) Data is inserted at the specified location
2 List .append (data) At the end of the additional data
3 List 1.extend (Table 2) The data is added to the list of the list 1 2

 

2. Modify the list data

No. Keyword / function / method Explanation
1 List [index] = data Modify the specified index data

 

3. Delete list data

No. Keyword / function / method Explanation
1 del list [index] Delete data specified index
2 List .remove (data) Remove the first occurrence of data
3 List .pop () Delete end of the data
4 List .pop (index) Deletes the specified index data
5 List .clear () clear the list

 

4. A list of statistical data

No. Keyword / function / method Explanation
1 len (list) List Length
2 List .count (data) The number of times the data appear in the list

 

The ordered list data

No. Keyword / function / method Explanation
1 List .sort () Ascending
2 List .sort (reverse = True) Sort Descending
3 List 1.reverse () Reverse, flip

Guess you like

Origin www.cnblogs.com/summer1019/p/11234175.html