列表的定义:存储多个有序的数据

注意:列表可以是任意的数据类型

列表的索引和切片

列表的索引和切片和字符串的索引和切片有什么相同点和不同点呢?
列表的索引和切片和字符串的用法和作用是一样的
列表的索引取出来的数据类型,该元素是什么类型,就是什么类型
列表的嵌套

列表的增删改查
append():追加到最后

insert():新增到指定的位置,通过索引添加

extend:添加多个

remove:删除指定的值

pop:通过索引删除指定的值,默认删除最后一个

del:很少用

修改元素

reverse():倒序

sort():按照从小到大的顺序排序

元组的表示
空元组

注意:一个元素的元组,必须加逗号

注意:元组不可修改,不能进行新增、修改、删除、排序,适合用来做一些限制的操作

网友评论