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

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

3、比如在这个列表中a = [1,0.2,'hello',[1,2,3],True]获取hello
a = [1,0.2,'hello',[1,2,3],True]
print(a[2])

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

5、扩展,什么时候的时候用列表
(如果你要存储的数据 是一个类型的 建议用列表)
6、列表中增加数据 .append
a = [1,0.2,'hello',[1,2,3],True]
a.append('nihao')
print("a列表的值{0}".format(a))

7、append 追加 追加在末尾 每次只能添加一个
8、insert 插入数据 想放哪就放那 但是必须指定位置
a = [1,0.2,'hello',[1,2,3],True
a.insert(2,"jjj")
print("a列表的值{0}".format(a))
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。