python实现从字典中删除元素的方法
2015-05-04 09:59
971 查看
python的字典可以通过del方法进行元素删除,下面的代码详细演示了这一过程
# Create an empty dictionary d = {} # Add an item d["name"] = "Fido" assert d.has_key("name") # Delete the item del d["name"] assert not d.has_key("name") # Add a couple of items d["name"] = "Fido" d["type"] = "Dog" assert len(d) == 2 # Remove all items d.clear() assert len(d) == 0
希望本文所述对大家的Python程序设计有所帮助。
您可能感兴趣的文章:
- Python 字典(Dictionary)操作详解
- python中的字典详细介绍
- python两种遍历字典(dict)的方法比较
- python通过字典dict判断指定键值是否存在的方法
- python提取字典key列表的方法
- Python中字典创建、遍历、添加等实用操作技巧合集
- Python中字典和JSON互转操作实例
- Python中使用item()方法遍历字典的例子
- python中将字典转换成其json字符串
- python 将字符串转换成字典dict
- Python字符串、元组、列表、字典互相转换的方法
- python实现给字典添加条目的方法
- Python中让MySQL查询结果返回字典类型的方法
- python创建和使用字典实例详解
- Python中实现两个字典(dict)合并的方法
- Python 字典与字符串的互转实例
- Python中实现字符串类型与字典类型相互转换的方法
- Python字典创建 遍历 添加等实用基础操作技巧
相关文章推荐
- python实现从字典中删除元素的方法
- Python简单遍历字典及删除元素的方法
- Python实现列表删除重复元素的三种常用方法分析
- Python实现连接两个无规则列表后删除重复元素并升序排序的方法
- Python 删除字典元素的4种方法
- python实现删除文件与目录的方法
- 构造一个特殊栈,实现方法getmin,返回栈中的最小元素 Python版
- Python实现字典按照value进行排序的方法分析
- python创建列表和向列表添加元素的实现方法
- python中List添加、删除元素的几种方法
- Python三种方法删除列表中的元素
- Java 基本数组删除特定元素的实现方法
- Python cookbook(数据结构与算法)找到最大或最小的N个元素实现方法示例
- Python cookbook(数据结构与算法)实现查找两个字典相同点的方法
- Python 字典删除元素clear、pop、popitem
- python中字典删除元素
- 统计元素个数+字典存入文件(通过序列化)的python实现
- 面试题---请写出一段Python代码实现删除一个list里面的重复元素
- Python实现变量数值交换及判断数组是否含有某个元素的方法
- Python有序字典简单实现方法示例