序号 | 分类 | 关键字/函数/方法 | 描述 |
1 | 新增 | list.insert(索引,数据) | 在指定位置插入数据 |
list.append(数据) | 在list末尾追加数据 | ||
list.extend(list2) | 将list2的数据追加到list | ||
2 | 修改 | list[索引] = 数据 | 修改指定索引的数据 |
3 | 删除 | del list[索引] | 删除指定索引的数据 |
list.remove[数据] | 删除第一个出现的指定数据 | ||
list.pop | 删除末尾的数据 | ||
list.pop(索引) | 删除指定索引的数据 | ||
list.clear | 清空列表 | ||
4 | 统计 | len(list) |
统计列表长度 |
list.count(数据) | 统计指定数据在列表中出现的次数 | ||
5 | 排序 | list.sort() | 按升序排列 |
list.sort(reverse=True) | 按降序排列 | ||
list.reverse() | 逆序、反转 |
使用示例: