python dict操作
2024-09-04 17:22:58
d1 = {'one': 1, 'two': 2}
d2 = {'one': 1, 'two': 2}
d3 = {'one': 1, 'two': 2}
print(dir(d1)) # 1、contians
print('one' in d1) # 2、eq
print(d1 == d2) # 3、len
print(len(d1)) # 4、ne
print(d1 != d2) # 5、iter
print(iter(d1)) # 6、clear
d3.clear()
print(d3) # 7、copy
d4 = d1.copy()
print(d4) # 8、fromkeys
l = [1, 2, 3]
d5 = dict.fromkeys(l, 'w')
print(d5) # 9、get
print(d1.get('one'))
print(d1.get('three', 3)) # 10、items
print(d1.items()) # 11、keys
print(d1.keys()) # 12、pop
d = d1.pop('three', 3)
print(d)
print(d1)
d = d1.pop('one')
print(d)
print(d1) # 13、popitem
d = d2.popitem()
print(d)
print(d2) # 14、setdefault
d = d2.setdefault('one')
print(d)
print(d2)
d = d2.setdefault('three', 3)
print(d)
print(d2) # 15、update
d1.update({'three': 3})
print(d1) # 16、values
print(d1.values())
最新文章
- git基本配置
- [redis] Node is not empty. Either the node already knows other nodes
- order_by_、group_by_、having的用法区别
- php程序员的水平 看看自己属于那个级别的
- MYSQL 下一些常用操作命令:新建用户、修改密码、修改登录host等
- Maven搭建webService (三) 创建客户端---使用Apache CXF方式实现
- WPF 绑定四(层级绑定)
- Java基础知识强化之集合框架笔记21:数据结构之 数组 和 链表
- 使用Python做科学计算初探
- cf C. Bombs
- Shell 传递参数
- nefu117 素数个数的位数,素数定理
- MySQL启动出现The server quit without updating PID file错误解决办法
- 7. svg学习笔记-图案和渐变
- Eclipse启动错误JVM terminated. exit code 1解决方法
- [C++]2-1 水仙花数
- activiti学习第二天
- Excel、VBA与MySQL交互
- 深入理解L1、L2正则化
- Salesforce的翻译工作台