python数据结构 - 字典
2019-03-12 12:16
106 查看
文章目录
字典的定义
定义:是一个内置的数据结构,允许将数据与键而不是数字关联,这样可以使内存中的数据与实际数据的结构保持一致。
别名:映射、散列、关联数组
特性:
- 可以动态扩展存储额外的键值对
- 会维护关联关系
- 不会维持插入的顺序
字典的相关操作
创建字典
>>> dictionary_1={} >>> dictionary_2 =dict() >>> type(dictionary_1) <class 'dict'> >>> type(dictionary_2) <class 'dict'>
增加数据
>>> dictionary_1['name'] = 'John' >>> dictionary_1['birthday'] = '2012-10-22' >>> dictionary_1['name'] 'John' >>> dictionary_2 = {'name' : 'Merry','birthday': '2012-10-22','hobby':['swim','play','read']} >>> dictionary_2['name'] 'Merry' >>> dictionary_2['hobby'] ['swim', 'play', 'read'] >>> dictionary_2['hobby'][0] 'swim' >>> dictionary_1['number'] = '123' >>> dictionary_2['number'] = [123,2,3] >>> dictionary_1 {'name': 'John', 'birthday': '2012-10-22', 'number': '123'} >>> dictionary_2 {'name': 'Merry', 'birthday': '2012-10-22', 'hobby': ['swim', 'play', 'read'], 'number': [123, 2, 3]}
相关文章推荐
- python数据结构之字典
- Python 3.6 学习--基础6:数据结构--del声明,元组和序列,集合,字典
- 基础篇12-python基本数据结构-字典
- Python数据结构之映射(內建字典)
- python数据结构(列表、元组、字典)
- 3.数据结构-Python内置类型方法性能分析(python列表和字典操作复杂度)
- Python自学1:Python 基本数据结构:列表、元组、字典
- A Byte of Python 笔记(7)数据结构:列表、元组、字典,序列
- Numpy学习(2):将cifar10/100数据文件读入到python数据结构(字典)中
- python基础知识——内置数据结构(字典)
- Python数据结构:序列(列表[]、元组())与映射(字典{})语法总结
- Python数据结构-字典
- Python数据结构——列表、元组及字典
- Python实现列表转换成字典数据结构的方法
- Python数据结构-字典
- Python培训知识总结系列- 第二章Python数据结构第四部分-字典操作
- Python中列表、字典、元组、集合数据结构整理
- Python基础知识(二)基本数据结构list列表和dict字典
- Python数据结构:序列(列表[]、元组())与映射(字典{})语法总结
- python基础系列教程——数据结构(列表、元组、字典、集合、链表)