The relationship between python tuples and lists_python tuples and lists_weixin_39576149’s blog
Slice view names = [“#ZhangYang”,”4Guyun”,”Xiangpeng”,”ChenRonghua”,”XuLiangChen”] print(names) print(names[1:3]) ##Slicing; regardless of the head and tail print(names[0:3]) print(names[-1]) print(names[-2:]) print(names[:3]) print(names[0],names[2]) D:\python35\python.exe D:/PycharmProjects/zhuyouen/0403/names.py [‘#ZhangYang’, ‘4Guyun’, ‘Xiangpeng’, ‘ChenRonghua’, ‘XuLiangChen’] [‘4Guyun’, ‘Xiangpeng’] [‘#ZhangYang’, ‘4Guyun’, ‘Xiangpeng’] XuLiangChen [‘ChenRonghua’, ‘XuLiangChen’] [‘#ZhangYang’, ‘4Guyun’, ‘Xiangpeng’] #ZhangYang Xiedi Append names = [“#ZhangYang”,”4Guyun”,”Xiangpeng”,”ChenRonghua”,”XuLiangChen”] print(names) names.append(‘LeiHaidong’) D:\python35\python.exe D:/PycharmProjects/zhuyouen/0403/names.py [‘#ZhangYang’, ‘4Guyun’, ‘Xiangpeng’, ‘ChenRonghua’, ‘XuLiangChen’] [‘#ZhangYang’, ‘4Guyun’, ‘Xiangpeng’, ‘ChenRonghua’, ‘XuLiangChen’, ‘LeiHaidong’] Insert names = [“#ZhangYang”,”4Guyun”,”Xiangpeng”,”ChenRonghua”,”XuLiangChen”] print(names) names.append(‘LeiHaidong’) names.insert(1,”ChenRonghua”) names.insert(3,”XingZhiyu”) D:\python35\python.exe D:/PycharmProjects/zhuyouen/0403/names.py [‘#ZhangYang’, ‘4Guyun’, ‘Xiangpeng’, ‘ChenRonghua’, ‘XuLiangChen’] [‘#ZhangYang’, ‘ChenRonghua’, ‘4Guyun’, ‘XingZhiyu’, ‘Xiangpeng’, ‘ChenRonghua’, ‘XuLiangChen’, ‘LeiHaidong’] Replace names = [“#ZhangYang”,”4Guyun”,”Xiangpeng”,”ChenRonghua”,”XuLiangChen”] print(names) names.append(‘LeiHaidong’) names.insert(1,”ChenRonghua”) names.insert(3,”XingZhiyu”) names[2] =’Xiedi’ D:\python35\python.exe D:/PycharmProjects/zhuyouen/0403/names.py [‘#ZhangYang’, ‘4Guyun’, ‘Xiangpeng’, ‘ChenRonghua’, ‘XuLiangChen’] [‘#ZhangYang’, ‘ChenRonghua’, ‘Xiedi’, ‘XingZhiyu’, ‘Xiangpeng’, ‘ChenRonghua’, ‘XuLiangChen’, ‘LeiHaidong’] Delete Method 1: names = [“#ZhangYang”,”4Guyun”,”Xiangpeng”,”ChenRonghua”,”XuLiangChen”] print(names) names.append(‘LeiHaidong’) names.insert(1,”ChenRonghua”) names.insert(3,”XingZhiyu”) names[2] =’Xiedi’ print(names) #delete(three methods) names. remove(‘ChenRonghua’) #del names[1]=names. pop(1) #names.pop(1) print(names) D:\python35\python.exe D:/PycharmProjects/zhuyouen/0403/names.py [‘#ZhangYang’, ‘4Guyun’, ‘Xiangpeng’, ‘ChenRonghua’, ‘XuLiangChen’] [‘#ZhangYang’, ‘ChenRonghua’, ‘Xiedi’, ‘XingZhiyu’, ‘Xiangpeng’, ‘ChenRonghua’, ‘XuLiangChen’, ‘LeiHaidong’] [‘#ZhangYang’, ‘Xiedi’, ‘XingZhiyu’, ‘Xiangpeng’, ‘ChenRonghua’, ‘XuLiangChen’, ‘LeiHaidong’] Method 2: names = [“#ZhangYang”,”4Guyun”,”Xiangpeng”,”ChenRonghua”,”XuLiangChen”] print(names) names.append(‘LeiHaidong’) names.insert(1,”ChenRonghua”) names.insert(3,”XingZhiyu”) names[2] =’Xiedi’ print(names) #delete(three methods) #names. remove(‘ChenRonghua’) #del names[1]=names. pop(1) del names[1] #names.pop(1) print(names) D:\python35\python.exe D:/PycharmProjects/zhuyouen/0403/names.py [‘#ZhangYang’, ‘4Guyun’, ‘Xiangpeng’, ‘ChenRonghua’, ‘XuLiangChen’] [‘#ZhangYang’, ‘ChenRonghua’, ‘Xiedi’, ‘XingZhiyu’, ‘Xiangpeng’, ‘ChenRonghua’, ‘XuLiangChen’, ‘LeiHaidong’] [‘#ZhangYang’, ‘Xiedi’, ‘XingZhiyu’, ‘Xiangpeng’, ‘ChenRonghua’, ‘XuLiangChen’, ‘LeiHaidong’] Method Three: names = [“#ZhangYang”,”4Guyun”,”Xiangpeng”,”ChenRonghua”,”XuLiangChen”]…