How to understand the general operation of list in Python
This article focuses on "how to understand the general operation of lists in Python". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to understand the routine operation of lists in Python.
Catalogue
1. An introduction to the list
two。 Print out the data of the list
1. We can print according to the subscript value.
two。 Traversing using for loops
3. Traversing using while loops
3. Add operation of list
1.append () method
2.extend () method
3.insert () method
4. List modification operation
5. Lookup operation of list
1.in method
2.not in method
3.index method
4.count method
6. Delete operations in the list
1.del method
2.pop method
3.remove method
7. Sort operation of list
8. A little exercise is for you.
(1)
(2)
1. An introduction to the list
Format of list: the type of variable An is list
NamesList = ['xiaoWang','xiaoZhang','xiaoHua']
The elements in the list can be of different types
For example: testlist= [1]
two。 Print out the list of data 1. We can print namesList = ['xiaoWang','xiaoZhang','xiaoHua'] print (namesList [0]) print (namesList [1]) print (namesList [2]) according to the subscript value.
two。 Use the for loop to iterate through namesList = ['xiaoWang','xiaoZhang','xiaoHua'] for i in namesList: print (I)
3. Use the while loop to iterate through namesList = ['xiaoWang','xiaoZhang','xiaoHua'] length=len (namesList) i=0while I