标签:python
#!/usr/bin/env pythonname = ["A","B","C","D",9,10,11,12,9,3,4,5,6,10,100,"Class","Delete","jack","jason","xiaoli","Baige","tiandi","angege","jack"]
print(name)
print (name[-4])
print (name[3])
print (name[0])
print (name[0:2]) # 从0开始到第二个值
print (name[-2:])
print (name[:3])
print (name[16:18][1][2])
name.insert(2,‘tom‘)
print(name)
name.append("BAIDU")
print(name)
name.remove("B")
print(name)
print(name[3:7]) # 取出第四至第七个人
del name[2]
print(name)
print(name[0::2]) # 步长
print( "A" in name)
if ‘jack‘in name: # 判断是否存在一个列表中
print("jack in this list")
name_of_c = name.count(‘jack‘)
print("[%s]jack is name"%name_of_c)
change_vaule = name.index("jack")
name[change_vaule] = 999
print (name[change_vaule])
print(name)
print(name.count(9))
for i in range(name.count(9)): # 统计出现9的次数来决定循环次数
change_date = name.index(9) # 取出9这个值
name[change_date] = 199999999 # 并修改这个值
print (name)
name2 =["A","B","C","D",9,10,11]
name.extend(name2) #扩展进来一个新的列表
print (name)
print(name2)
name.reverse() #反序
print (name)
name.pop(3) #移除某项
print (name)
name.sort() #py3.0不支持数值与字符串一起排序;
print(name)
标签:python
原文地址:http://blog.51cto.com/miller0intarnet/2117171