1. 修改指定下标数据
name_list = ['pgone', 'keyng', 'jonyj', 'vava'] # 结果:['pgone', 'aaa', 'jonyj', 'vava'] name_list[1] = 'aaa' print(name_list)
2. 逆序:reverse()
str1 = [1, 5, 3, 7, 6, 2, 4] # 结果:[4, 2, 6, 7, 3, 5, 1] str1.reverse() print(str1)
3. 排序:sort()
语法:列表序列.sort(key = None, reverse=False)
注意:reverse表示排序规则,reverse =True降序,reverse = False升序(默认)
str2 = [1, 5, 3, 7, 6, 2, 4] # 结果:[1, 2, 3, 4, 5, 6, 7] str2.sort() # 结果:[7, 6, 5, 4, 3, 2, 1] str2.sort(reverse=True) print(str2)
4. 复制:copy()
name_list = ['pgone', 'keyng', 'jonyj', 'vava'] str1 = name_list.copy() # 结果:['pgone', 'keyng', 'jonyj', 'vava'] print(str1) # 结果:['pgone', 'keyng', 'jonyj', 'vava'] print(name_list)
标签:pgone,reverse,str1,list,列表,---,复制,vava,name From: https://www.cnblogs.com/yz-b/p/16597025.html