python 列表list【】

时间:2026-02-13 00:28:16

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]获取hello

a = [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、列表中增加数据 .append

a = [1,0.2,'hello',[1,2,3],True]


a.append('nihao')
print("a列表的值{0}".format(a))

python 列表list【】

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

8、insert  插入数据  想放哪就放那 但是必须指定位置

a = [1,0.2,'hello',[1,2,3],True


a.insert(2,"jjj")
print("a列表的值{0}".format(a))
© 2026 五度知识库
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com