list(‘hello‘) [‘h‘,‘e‘,‘l‘,‘l‘,‘o‘]
字符列表转化为字符串:str = ‘‘.join(list)
x = [1,1,1] x[1] = 2 x Out: [1,2,1]
names = [‘a‘,‘b‘,‘c‘] del names[2] names Out: [‘a‘,‘b‘]
> del 关键字的本质是用来将一个变量从内存中删除
> 日常开发中,要从列表中删除数据,建议使用列表提供的方法
append count insert reverse clear extend pop sort copy index remove
序号 | 分类 | 关键字/函数/方法 | 说明 |
1 | 增加 | list.insert(index, data) | 在指定位置插入数据 |
list.append(data) | 在末尾追加数据 | ||
list1.extend(list2) | 将列表2的数据追加到列表1 | ||
2 | 修改 | list[index] = data | 修改指定索引的数据 |
3 | 删除 | del list[index] | 删除指定索引的数据 |
list.remove[data] | 删除第一个出现的指定数据 | ||
list.pop() | 删除末尾数据 | ||
list.pop(index) | 删除指定索引数据 | ||
list.clear() | 清空列表 | ||
4 | 统计 | len(list) | 列表长度 |
list.count(data) | 数据在列表中出现的次数 | ||
5 | 排序 | list.sort() | 升序排序 |
list.sort(reverse=True) | 降序排序 | ||
list.reverse() | 逆序、反转 |
原文:https://www.cnblogs.com/chan-shi/p/10476351.html