python-列表和切片
列表和列表切片:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 name = ["a","b","c","d"] 2 #从0开始数 3 print(name) 4 print(name[0])#第0个 5 print(name[0:3])#第0个到第2个 = print(name[:3]) 6 print(name[2:])#第2个到最后 7 print(name[-1])#最后一个
增删改查:
name = ["a","b","c","d"] name.append("Elif") #增加 name.insert(1,"decie")#插入 name[2] = "222"#改 # name.remove("222") # print(name) # del name[1] # print(name) #del name[1] = name.pop[1] # name.pop()#不输入下标,默认删除最后一个 # print(name) #查 print(name.index("222"))#获得索引 # print(name[name.index("222")])#通过索引获得值 print(name.count("222"))#统计 # name.clear()#清空 name.reverse()#反转 name.sort()#排序,按照ASCII码顺序来排列 name2 = [1,2,3,4] name.extend(name2)#合并列表 print(name,name2)