names = ['a','b','c','d','e','f','g'] print(names) #修改元素: names[0]='A' print(names) #追加元素: names.append('h') print(names) #插入元素: names.insert(3,'j') print(names) #移除元素: names.remove("j") print(names) del names[3] print(names) #查询元素的索引值: print(names.index("b")) #删除最后一个元素: names.pop() print(names) #删除指定索引的元素: names.pop(1) print(names) #清空names: names.clear() print(names) names = ['a','b','c','d','e','f','g'] #统计元素li的个数: print(names.count("c")) #反转元素顺序: names.reverse() print(names) #排序元素: names.sort() print(names) #将列表names2的元素合并到names: names = ['a','b','c','d','e','f','g'] names2 = [1,2,3] names.extend(names2) #合并后names2列表继续存在 print(names) #将列表删除: del names2 #复制列表,两个列表完全独立 names2 = names.copy() print (names2) #将列表的奇数索引切片: names = ['a','b','c','d','e','f','g','h'] print(names[0:-1:2]) #从索引0开始到索引最后一个,索引步长值为2 print(names[::2]) #与上面等效