#列表
names = ["Zhangwuji","Zhaomin","Yangguo","Xiaolongnv","Guojing","Huangrong"]
# print(names)
# print(type(names))
#切片
# print(names[1]) #在列表中取出zhaomin,列表中下村从0开始,[0,1,2,3,4,5.....]
#切片中顾头不顾尾
# print(names[:2]) #取当前列表中第一个值,第二个值
# print(names[2:4]) #取当前列表中yangguo,xiaolongnv,
#切片中自右而左数,默认是从-1开始
# print(names[-1]) #取当前列表中最后一个值
# print(names[-2:]) #取当前列表中倒数两个值
# print(names.index("Zhaomin")) #通过值来查找其对应的下标
# names.append("Huanglaoxie") #按顺序追加到当前列表中
# names.insert(1,"Zhouzhiruo") #在指定的位置插入数据
# names[1]="Hahaha" #改变列表中的值
#删除列表中的值
# names.remove("Zhaomin") #删除指定的值
# del names[1] #删除指定下标位置的值
# names.pop(1) # 删除指定的下标位置的值,如果不加下标,默认删除最后一个值
# names.clear() #清空列表
# print(names.count("Zhaomin")) #统计某个值出现的次数
# names.reverse() #反转列表
name2 = [1,2,3,4,5]
# names.extend(name2) #合并列表
print(name2)
#浅copy
# names = ["Zhangwuji","Zhaomin",["tom","jack"],"Yangguo","Xiaolongnv","Guojing","Huangrong"]
# name2 = names.copy()
# names[2][0] = "TOM"
# names[1] = "赵敏"
# print(names)
# print(name2)
#深copy
# import copy
# names = ["Zhangwuji","Zhaomin",["tom","jack"],"Yangguo","Xiaolongnv","Guojing","Huangrong"]
# name2 = copy.deepcopy(names)
# names[2][0] = "TOM"
# names[1] = "赵敏"
# print(names)
# print(name2)
#跳着切片
# a = [1,2,3,4,5,6]
# print(a[0:-1:2])
# print(a[::2])
原文地址:http://blog.51cto.com/limingyu/2103490