python 列表list【】

时间:2024-10-12 07:41:15

1、空列表a=【】print(a)

python 列表list【】

2、查看列表最后一个元素a = [1,0.2,'hello',[1,2,3],True]print(a[-1])

python 列表list【】

3、比如在这个谱驸扌溺列表中a = [1,0.2,'hello',[1,2,3],True]获取helloa = [1,0.2,'hello',[1,2,3柯计瓤绘],True]print(a[2])

python 列表list【】

4、列表的切片 同字符串的操作 列表名【索引头:索引尾:步长】比如取步长2的所有元素a = [1,0.2,'hello',[1,2,3],True]print(a[::2])

python 列表list【】

5、扩展,什么时候的时候用列表(如果你要存储的数据 是一个类型的 建议用列表)

6、列表中增加数据 .appenda = [1,0.2,'hello'挢旗扦渌;,[1,2,3],True]a.app髫潋啜缅end('nihao')print("a列表的值{0}".format(a))

python 列表list【】

7、append 追加 追加在末尾 每次只能添加一个

8、insert 插入数倌栗受绽据 想放哪就放那 但是必须指定位置a = [1,0.2,'hello',[1,2,3],Truea.insert(2,"jjj")print("a列表的值{0}".format(a))

© 手抄报圈