This article mainly introduces: the main application of the list in Python and some functions of the list comes with
Code:
#!/usr/bin/env python
# Author by LH
#-*-Coding:utf-8-*-
Name_list=[' al ', ' Ed ', ' FG ']
Print Name_list #打印列表
Print Name_list[0] #索引
Print Name_list[0:2] #切片
For i in Name_list: #for循环打印
Print I
Name_list.append (' Ed ') #添加
Print Name_list
I=name_list.count (' Ed ') #统计相同的字符有几个
Print I
temp=[' FG ', ' FG ', ' FG ']
Name_list.extend (temp) #批量添加
Print Name_list
Print Name_list.index (' al ')
#获取指定字符串的索引位置
Name_list.insert (1, ' SX ')
Print Name_list
A1=name_list.pop () #移除最后一个
Print A1
Name_list.remove (' Ed ') #移除想要删除的字符串 (the default is to remove the first from left to right if you have the same)
Print Name_list
Name_list.reverse () #将字符串反过来打印 (reverse)
Print Name_list
Del Name_list[0:4] #删除指定位置的字符串 (both indexes and slices apply)
Print Name_list
Operation Result:
Application of list in Python