Python 字典

Python字典详解

Python 字典

1、字典可以看作是无序的列表集合,字典是通过键来存取,而不是通过偏移来存取。

2、任意对象的无序集合,可变长、异构、任意嵌套。

3、属于可变映射类型(key-value),但不支持序列操作(合并,分片)。

4、字典基本操作

In [1]: D={'001':'egg','002':'apple','003':'orange','004':'banana','000':'minion'}

In [2]: D['002']
Out[2]: 'apple'

In [3]: D
Out[3]:
{'000': 'minion',
 '001': 'egg',
 '002': 'apple',
 '003': 'orange',
 '004': 'banana'}

In [4]: len(D)
Out[4]: 5

In [5]: 'orange' in D
Out[5]: False

In [6]: 'apple' in D
Out[6]: False

In [7]: '001' in D
Out[7]: True

In [9]: list(D.keys())
Out[9]: ['001', '002', '003', '004', '000']

In [10]: D['003']=['good orange','bad orange']

In [11]: D
Out[11]:
{'000': 'minion',
 '001': 'egg',
 '002': 'apple',
 '003': ['good orange', 'bad orange'],
 '004': 'banana'}

In [12]: del D['000']

In [13]: D
Out[13]:
{'001': 'egg',
 '002': 'apple',
 '003': ['good orange', 'bad orange'],
 '004': 'banana'}

In [14]: D['000']='minion'

In [15]: D
Out[15]:
{'000': 'minion',
 '001': 'egg',
 '002': 'apple',
 '003': ['good orange', 'bad orange'],
 '004': 'banana'}

 

转载于:https://www.cnblogs.com/matplot/p/7113312.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值