1. Create a list
>>> list1 = [' Anmi ', ' kan ', ' seven ']
2. View the list
>>> list1[' Anmi ', ' kan ', ' seven ']>>> list1[0] ' Anmi ' >>> list1[1] ' kan ' >>> list1[2] ' Seven '
3. Append elements
>>> list1.append (' Selina ') >>> list1.append (' kan ') #元素值可以重复 >>> List1
4. Index
>>> list1[' Anmi ', ' kan ', ' Seven ', ' Selina ', ' kan ']>>> list1.index (' kan ') 1 #从左开始查找到第一个匹配的后, on output
5. Statistics
>>> list1.count (' kan ') 2>>>
6. Insert
>>> List1.insert (2, ' Eric ') >>> list1[' Anmi ', ' kan ', ' Eric ', ' Seven ', ' Selina ', ' Kan ']
7. Delete the last element
>>> list1.pop () ' Kan '
8. Delete the specified element
>>> list1[' Anmi ', ' kan ', ' Eric ', ' Seven ', ' Selina ']>>> list1.remove (' Eric ') >>> list1[' Anmi ', ' kan ', ' Seven ', ' Selina '] Delete all specified elements list1 = [' kan ', ' Seven ', ' Kan ', ' Eric ', ' kan ']for i in range (list1.count (' kan ')): List 1.remove (' kan ') print (List1)
9. Reversal
>>> list1[' Anmi ', ' kan ', ' Seven ', ' Selina ']>>> list1.reverse () >>> list1[' Selina ', ' seven ', ' Kan ', ' anmi ']
10. Sorting
>>> list1.sort () >>> list1[' Anmi ', ' kan ', ' Selina ', ' seven ']
This article is from the "guoxianqi2016" blog, make sure to keep this source http://guoxianqi2016.blog.51cto.com/11407620/1762196
Python basic data Type-list