Python学习4-dict和set
来源:互联网 发布:win10重装linux子系统 编辑:程序博客网 时间:2024/05/19 09:14
转自廖雪峰的讲义
dict
dict使用键-值(key-value)存储,具有极快的查找速度,但比较占内存。
1、可以用如下方式创建dict:
d = {'Michael': 95, 'Bob': 75, 'Tracy': 85}
2、向dict中加入key:
d['Adam'] = 67
3、删除dict中的key:
d.pop('Bob')
4、查询Key是否存在于dict中:
'Thomas' in d
d.get('Thomas', -1)
5、dict的key必须是不可变对象,在Python中,字符串、整数等都是不可变的,因此,可以放心地作为key。
set
set是一组key的集合
1、可以用如下方式创建set
s = set([1, 2, 3])
2、将元素添加到set中
s.add(4)
3、从set移除元素
s.remove('a')
0 0
- Python学习4-dict和set
- Python Dict和Set(4)
- Python学习五:dict 和 set
- Python学习笔记 - dict和set
- python学习笔记 使用dict和set
- python学习笔记3--dict和set
- Python dict,set学习
- python dict和set
- Python dict和set
- python学习(6)python基础、使用dict和set
- Python学习-Dict and Set
- Python--使用dict和set
- Python(Dict和Set类型)
- python:中dict和set
- 【Python】6“dict和set“
- python dict 和set 详解
- Python list,Dict和Set
- python dict和set 用法
- pat 1065. A+B and C (64bit)
- 学习小结
- 关于三角函数、反三角函数在VC和linux gcc下的编译
- java中迭代器的用法
- 静态变量的加载
- Python学习4-dict和set
- first-of-type,nth-of-type,last-of-type分类问题
- Max Sum of Max-K-sub-sequence
- IMWeb前端学习笔记——Day3
- UDP丢包原因
- [图解法结合源码]理解、记忆Handler、Looper、MessageQueue之间的关系
- mySQL2
- [Conclusion]RabbitMQ-客户端源码之总结
- G