码迷,mamicode.com
首页 > 编程语言 > 详细

Python 字典

时间:2017-07-03 23:56:09      阅读:302      评论:0      收藏:0      [点我收藏+]

标签:minion   bad   基本   min   color   nbsp   value   列表   false   

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}

 

Python 字典

标签:minion   bad   基本   min   color   nbsp   value   列表   false   

原文地址:http://www.cnblogs.com/matplot/p/7113312.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!