pythonList列表
发布时间:2024年01月23日
List列表
一、学会创建一个列表
列表是最常用的 Python 数据类型,它可以作为一个方括号内的逗号分隔值出现。

二、学会如何访问列表中的值。


三、使用[]的形式来截取字符。
[i,j]代表的是从i一直截取到j-1的元素。
正向索引(是从左往右的第一位索引值为0):


反向索引(从右往左索引值第一位是-1):


四、更新
(1)更新列表:对列表的数据项进行修改或更新,使用append()方法来添加列表项。


(2)list.extend(seq):在列表末尾一次性追加另一个序列中的多个值(用新列表扩展原来的列表)


(3)append()与extend()的区别
Append是将新序列整体作为一个新的元素添加到原列表的末尾。
Exend仅仅向原列表末尾提娜佳新序列中的值。


五、删除列表元素
可以使用del语句来删除列表中的元素


六、list.insert(index,obj):将对象插入列表
Index:对象需要插入的索引位置
Obj:要插入列表中的对象
注意:插入是插在索引位置之前(索引是从0开始的)


文章来源:https://blog.csdn.net/qq_61914592/article/details/135739507
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:chenni525@qq.com进行投诉反馈,一经查实,立即删除!