python--字典
来源:互联网 发布:ps淘宝美工教程百度云 编辑:程序博客网 时间:2024/05/09 21:34
>>> a = {1:'one',2:'two',3:'three'}
>>> a
{1: 'one', 2: 'two', 3: 'three'}
>>> b = a.copy()
>>> b
{1: 'one', 2: 'two', 3: 'three'}
>>> a
{1: 'one', 2: 'two', 3: 'three'}
>>> id(a)
47139216
>>> id(b)
47182688
>>> c = a
>>> id (c)
47139216
>>> a.clear()
>>> a
{}
>>> b
{1: 'one', 2: 'two', 3: 'three'}
>>> c
{}
>>>
>>>
>>>
>>> a.pop(2)
Traceback (most recent call last):
File "<pyshell#80>", line 1, in <module>
a.pop(2)
KeyError: 2
>>> b.pop(2)
'two'
>>> b
{1: 'one', 3: 'three'}
>>> a.popitem()
Traceback (most recent call last):
File "<pyshell#83>", line 1, in <module>
a.popitem()
KeyError: 'popitem(): dictionary is empty'
>>> b.popitem()
(3, 'three')
>>> b
{1: 'one'}
>>> a
{1: 'one', 2: 'two', 3: 'three'}
>>> b = a.copy()
>>> b
{1: 'one', 2: 'two', 3: 'three'}
>>> a
{1: 'one', 2: 'two', 3: 'three'}
>>> id(a)
47139216
>>> id(b)
47182688
>>> c = a
>>> id (c)
47139216
>>> a.clear()
>>> a
{}
>>> b
{1: 'one', 2: 'two', 3: 'three'}
>>> c
{}
>>>
>>>
>>>
>>> a.pop(2)
Traceback (most recent call last):
File "<pyshell#80>", line 1, in <module>
a.pop(2)
KeyError: 2
>>> b.pop(2)
'two'
>>> b
{1: 'one', 3: 'three'}
>>> a.popitem()
Traceback (most recent call last):
File "<pyshell#83>", line 1, in <module>
a.popitem()
KeyError: 'popitem(): dictionary is empty'
>>> b.popitem()
(3, 'three')
>>> b
{1: 'one'}
0 0
- Python 字典
- python 字典
- Python:字典
- Python 字典
- python字典
- Python 字典
- python 字典
- python 字典
- Python 字典
- Python字典
- python 字典
- python字典
- python 字典
- python 字典
- python--字典
- python 字典
- python字典
- Python---字典
- C++多线程程序设计
- SQlite
- iOS开发 常用宏定义
- 数据结构1----逻辑结构与物理结构(霜之小刀)
- 周易六十四卦——风水涣卦
- python--字典
- 设计模式——策略模式
- HDU 1412 {A} + {B}
- C#使用MD5加密,DES加密解密的一个类
- Mysql之子查询和连接
- R语言-基本算数(二)
- kafka+java 伪分布式 之二
- javascript流程语句以及运算符,BOW操作图,以及学习路线图
- Codeforces 672C Recycling Bottles【极限思维+贪心枚举】