Step one:将赋值号(=)左边指定的内容删除
Step two:将包含在赋值号(=)右边的可迭代对象中的片段插入左边被删除的位置
其实它是分上面两个步骤实现的
>>> heroes = ['zhizhuxia','meilide','mieba','putao','chengzi']
>>> heroes[4]='baby'
>>> heroes
['zhizhuxia', 'meilide', 'mieba', 'putao', 'baby']
>>> heroes[3:] = ['boke','weibo','tengxun','jimei']
>>> heroes
['zhizhuxia', 'meilide', 'mieba', 'boke', 'weibo', 'tengxun', 'jimei']
1.排序,顺序排序sort()
>>> nums = [2,5,1,3,4,6,3]
>>> nums.sort()
>>> nums
[1, 2, 3, 3, 4, 5, 6]
2.排序,倒序排序reverse()
nums = [1, 2, 3, 3, 4, 5, 6]
>>> nums.reverse()
>>> nums
[6, 5, 4, 3, 3, 2, 1]
或者是nums.sort(reverse = True)
3.查找索引值
>>> nums = [4,2,5,3,6,8,0,4,3]
>>> nums.index(3)
3
>>> nums.index(3,0,8)
3
第一个参数是查找的参数,第二个和第三个参数是索引值的下标
4.copy(),浅拷贝
>>> nums = [4,2,5,3,6,8,0,4,3]
>>> nums_copy1 = nums.copy()
>>> nums_copy1
[4, 2, 5, 3, 6, 8, 0, 4, 3]
>>> nums_copy2 = nums[:]
>>> nums_copy2
[4, 2, 5, 3, 6, 8, 0, 4, 3]
>>>