List common ways of doing things
1. Insert content at the end of the list--appenda=[1,2,3,4,5,6]a.append (7) Results: a=[1,2,3,4,5,6,7] Note: The list contents can be any type 2, insert content in the list pointing position--inserta=[ 1,2,3,4,5,6,7]a.insert (3,5) Results: a=[1,2,3,5,4,5,6,7] 3. Add the elements of a list to the end of the list--extenda=[1,2,3,5,4,5,6,7]a.extend ([+ +]) Results: a=[1,2,3,5,4,5,6,7,1,2,3] Note: Extend () accepts a list parameter, adds an element of the argument list to the end of the list, append () takes an object parameter, adds the object to the end of the list eg:a.append ([ Three-way]) Result: a=[1,2,3,5,4,5,6,7,1,2,3,[1,2,3] [4] There are several identical--counta=[1,2,3,5,4,5,6,7,1,2,3,[1,2,3]]a.count in the statistics list (3 Results: 2, indicating that the ' 3 ' element has 2 5 in the list, where an element in the calculation list first appears in the list--indexa=[1,2,3,5,4,5,6,7,1,2,3,[1,2,3]]a.index (5) Results: 3, which means ' 5 ' The first occurrence in the list is 3 6, directly deleting an element in the list (the first occurrence of the element)--removea=[1,2,3,5,4,5,6,7,1,2,3,[1,2,3]]a.remove (5) Results: a=[ 1,2,3,4,5,6,7,1,2,3,[1,2,3]] 7, delete the element of a ' position ' in the list, and print out the deleted element--popa=[1,2,3,4,5,6,7,1,2,3,[1,2,3]]a.pop (3) Results: 4, Represents the Delete element on the list position ' 3 ', the deleted element is ' 4 ' a=[1,2,3,5,6,7,1,2,3,[1,2,3]
Python learning experience-basic knowledge (II.)