首页 > 其他 > 详细

list方法补充

时间:2019-12-17 20:50:47      阅读:73      评论:0      收藏:0      [点我收藏+]

在上一个随便我们写了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)
输出结果为:[‘张天赐‘, ‘小明‘, ‘小红‘, [‘刘德华‘, ‘谢娜‘], ‘刘飞‘]
 

list方法补充

原文:https://www.cnblogs.com/ztcbug/p/12056621.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!