增加 列表. insert((案引,数据) 在指定位置插入数据
列表. append(数据) 在末尾追加数据
列表 .extend(列表2) 将列表2的数据追加到列表
修改 列表.[索引]=数据 修改指定索引的数据
删除 del.列表森引 删除指定索引的数据
列表 .remove[数据] 删除第一个出现的指定数据
列表.pop 删除末尾数据
列表.pop(索引) 删除指定索引数据
列表.cear 清空列表
统计 len(列表) 列表长度
列表 .count(数据) 数据在列表中出现的次数
排序 列表.count(数据) 升序排序
列表 .sort(reverse=Tnue) 降序排序
列表 .reverse() 逆序、反转
name_list = ["zhangsan","lisi","wangwu"]
# 1.取值和取索引
# list index out of range 列表超出范围
print(name_list[2])
# 使用index方法需注意,如果传递的数据不在列表中,程序会出错!
print(name_list.index("wangwu"))
# 2.修改
name_list[1] = "李四"
# list assignment index out of range
# 列表指定的索引超出范围,程序会报错!
# name_list[3] = "网小二"
# 3.增加
name_list.append("王小二")
name_list.insert(1,"撒花")
temp_list = ["孙悟空","猪八戒","沙师弟"]
name_list.extend(temp_list)
# 4.删除
name_list.remove("wangwu")
# pop 方法默认可以把列表中最后一个元素删除
name_list.pop()
name_list.pop(3)
name_list.clear()
print(name_list)