列表操作
names = ["4ZhangYang", "#!Guyun","xXiangPeng",["alex","jack"],"ChenRonghua","XuLiangchen"]
print(names[0:-1:2])
print(names[::2])
print(names[:])
names.append("WangXin")#增
names.insert(1,"LiWei")#插
names[2] = "XieDi"#改
names.remove("Chen$onghua")#删除
del names[1]#删除
names.pop()#删除最后一个
names.pop(1)#等同del names[1]
print(names.index("XieDi"))#按值找下标
print(names.count("ChenRongHua"))#同名数量
names.clear()#清空
names.reverse()#反排列
names.sort()#排序
names2 = [1,2,3]
names.extend(names2)#合并其他列
del names2#删除列表
names3 =names.copy()#浅copy,拷贝第一层内容,再下层拷贝地址
names4 = names #列表拷贝,指向同一个内存地址,与变量不同
#要完整复制要用
import copy
names5 =copy.deepcopy(names)#深copy,复制内容一样的列表;copy.copy()为浅copy,
for i in names:
print(i)
#########################################
person=['name',['saving',100]]
'''
p1=copy.copy(person)#三种浅copy方式
p2=person[:]
p3=list(person)
'''
p1=person[:]
p2=person[:]
p1[0]='alex'
p2[0]='fengjie'
p1[1][1]=50
print(p1)
print(p2)
['alex', ['saving', 50]]
['fengjie', ['saving', 50]]