1. list function, a string into a list
2. Basic list operations
Edit list - to the element assigned to a particular use of the index notation elements assignment as x [1] = 2
Removing elements - you can use the del statement
1 name1 = ['a','d','g','h'] 2 name2 = ['1','2','3','4'] 3 del name1[1] 4 print(name1) 5 print(len(name1)) 6 7 del name2[1:3] 8 print(name2) 9 Print (len (NAME2)) 10 . 11 Results: 12 is [ ' A ' , ' G ' , ' H ' ] 13 is . 3 14 [ ' . 1 ' , ' . 4 ' ] 15 2
To slice assignments - and to assign multiple elements
1 name = list('Perl') 2 name[1:] = list('ython') 3 print(name) 4 结果: 5 ['P', 'y', 't', 'h', 'o', 'n']
To slice assignments - inserting a new element (in this case, the first slice tool index and the second index must be the same)
1 name = list('Perl') 2 name[1:1] = list('ython') 3 print(name) 4 结果: 5 ['P', 'y', 't', 'h', 'o', 'n', 'e', 'r', 'l']
3. The list of methods
The method is closely linked with the object (list, string, etc.) functions. Call the method:
object.method(arguments)
3.1 append - attach an object to the end of the list - P34
6. list function, a string into a list
7. Basic Operation List
Edit list - to the element assigned to a particular use of the index notation elements assignment as x [1] = 2
Removing elements - you can use the del statement
1 name1 = ['a','d','g','h'] 2 name2 = ['1','2','3','4'] 3 del name1[1] 4 print(name1) 5 print(len(name1)) 6 7 del name2[1:3] 8 print(name2) 9 Print (len (NAME2)) 10 . 11 Results: 12 is [ ' A ' , ' G ' , ' H ' ] 13 is . 3 14 [ ' . 1 ' , ' . 4 ' ] 15 2
To slice assignments - and to assign multiple elements
1 name = list('Perl') 2 name[1:] = list('ython') 3 print(name) 4 结果: 5 ['P', 'y', 't', 'h', 'o', 'n']
To slice assignments - inserting a new element (in this case, the first slice tool index and the second index must be the same)
1 name = list('Perl') 2 name[1:1] = list('ython') 3 print(name) 4 结果: 5 ['P', 'y', 't', 'h', 'o', 'n', 'e', 'r', 'l']