Today, Python's various data structures, such as list, dict,tuple,string and other common data structures, as well as their common methods and methods of use, are mentioned.
A list of lists
1, the definition of the list
Or:
New_list = [] #空列表
2. Print List
Use the index value to refer to a specific value in the list, as follows
3, list how to add elements
Insert (0, ' Shanghai '), which is the insertion of elements in the 0 position Shanghai, the list of existing elements corresponding to the backward position
Results:
4. Deleting elements
(1) The first method: Using Pop (index value), the example is equivalent to the 0 index position of the element is deleted,
# Cities.pop (3) #索引不能越界, or you will get an error.
Results:
(2) The second method of deleting elements
(3) The third method, using Del to delete the specified element
5. Clear the list
6. Modify the elements in the list
7. Querying list elements
List method:
List.index (' specified element ')
List.count (' specified element ')
8. List reversal
List method: List.reverse (), the return value is None
9. Sort the list
10. List Merge
11. How multidimensional arrays are given the elements in the list
By the level of the list, one layer at a level to take the value can
12, the length of the list
Use Len (), Python's built-in function, for list,string and more.
13. List Operation Example Program
Example 1:
Second, the list of slices
1, the use of slices
If range () is used, it is also Gu Tou regardless of tail:
2, the step use of slices
3. The difference between list.reverse () and list[::-1]
4, different slices of the same method, the same output results
Three, the slice of the string, the above section also applies to the string
Iv. Cycle of the list
1. Iterate through the list using loops
2. Looping through strings using loops
3. Iterate through two-dimensional arrays using loops
Example:
Python Learning note-day2-list