在上一个随便我们写了list 常用的方法,该随便为一些需要补充的内容
注:本次例子为:
student = ["张天赐","小明","小红",[“张杰”,"谢娜"],"刘飞"]
number = [1,2,3,9,5,6]
------------------------------------------------------------------------------分割线,以上为例子,以下为方法
1.copy使用方法:把A列表下内容复制到B列表下(浅copy,copy内存地址,非值,被copy者发生变化,copy后的也会跟着变化) (deep为深copy)
number2 = number.copy()
print(number)
print(number2)
输出结果:
[1, 2, 3, 9, 5, 6]
[1, 2, 3, 9, 5, 6]
2.student[n] = "哈哈哈":将任意下标的值改为任意内容
注:下标从0开始,student下标为0 = “张天赐” 以此类推
student[0] = "周润发"
print(student)
输出结果为:['周润发', '小明', '小红', '刘飞']
3.student[n][n] = “n” :修改列表中包含的列表字段
student[3][0] = "刘德华"
print(student)
输出结果为:['张天赐', '小明', '小红', ['刘德华', '谢娜'], '刘飞']