1, list.append (obj) adds a new object at the end of the list and adds only one element at a time.
>>> list = [123, ‘kobego‘, [1, 2, 3], (1, 2)]>>> list.append([24, 23])>>> list[123, ‘kobego‘, [1, 2, 3], (1, 2), [24, 23]]
2. List.extend (seq) You can add multiple list elements at the end of the list at once.
>>> list = [123, ‘kobego‘, [1, 2, 3], (1, 2)]>>> list.extend([24, 23])>>> list[123, ‘kobego‘, [1, 2, 3], (1, 2), 24, 23]
3, List.pop (obj=list[-1]) removes an element from the list (the default is the end element) and returns the value of the removed element.
>>> list = [123, ‘kobego‘, [1, 2, 3], (1, 2)]>>> list.pop()(1, 2)>>> list[123, ‘kobego‘, [1, 2, 3]]
4, List.remove (obj) removes the first occurrence of an element in the list without a return value.
>>> list = [123, ‘kobego‘, 123, [1, 2, 3], (1, 2)]>>> list.remove(123)>>> list[‘kobego‘, 123, [1, 2, 3], (1, 2)]
5. List.index (obj) finds the index position of the first occurrence of a value from the list, and the error is not found.
>>> list = [123, ‘kobego‘, 123, [1, 2, 3], (1, 2)]>>> list.index(123)0
6, List.insert (index, obj) inserts the specified object into the specified position in the list.
>>> list = [123, ‘kobego‘, 123, [1, 2, 3], (1, 2)]>>> list.insert(1, ‘kobego24‘)>>> list[123, ‘kobego24‘, ‘kobego‘, 123, [1, 2, 3], (1, 2)]
7. List.reverse () Reverses the order of the elements in the list.
>>> list = [123, ‘kobego‘, 123, [1, 2, 3], (1, 2)]>>> list.reverse()>>> list[(1, 2), [1, 2, 3], 123, ‘kobego‘, 123]
8, List.sort ([func]) to sort the original list.
>>> list = [‘james‘, ‘kobego‘, ‘curry‘]>>> list.sort()>>> list[‘curry‘, ‘james‘, ‘kobego‘]
Day05:python List Method