#!/usr/bin/env python
# Author:Veray Zhou
info = {
'stu1105': 'bhang',
'stu1103': 'aang',
'stu1104': 'xiao',
}
print(info)
print(info['stu1103'])
info['stu1103']='lilianjie'
print(info)
del info['stu1104']
print(info)
info.pop('stu1105')
print(info)
info.popitem()#随机删除
print(info)
info1 = {
'stu1105': 'bhang',
'stu1103': 'aang',
'stu1104': 'xiao',
'stu1106': {'a':1,'b':2}
}
print(info1.get('stu1103'))
print('stu1103' in info1)
print(info1.keys())
print(info1.values())
info1.setdefault('stu1104','hhhhh')#有就不插入,没有就插入
print(info1)
a={'stu1105': 'mm',
'cc':55}
info1.update(a)
print(info1)
print(info1.items())
c = dict.fromkeys([1,2,3],'test') #初始化一个新的字典
print(c)
for i in info1:
print(i,info1[i])
for k,v in info1.items():
print(k,v)
{'stu1105': 'bhang', 'stu1103': 'aang', 'stu1104': 'xiao'}
aang
{'stu1105': 'bhang', 'stu1103': 'lilianjie', 'stu1104': 'xiao'}
{'stu1105': 'bhang', 'stu1103': 'lilianjie'}
{'stu1103': 'lilianjie'}
{}
aang
True
dict_keys(['stu1105', 'stu1103', 'stu1104', 'stu1106'])
dict_values(['bhang', 'aang', 'xiao', {'a': 1, 'b': 2}])
{'stu1105': 'bhang', 'stu1103': 'aang', 'stu1104': 'xiao', 'stu1106': {'a': 1, 'b': 2}}
{'stu1105': 'mm', 'stu1103': 'aang', 'stu1104': 'xiao', 'stu1106': {'a': 1, 'b': 2}, 'cc': 55}
dict_items([('stu1105', 'mm'), ('stu1103', 'aang'), ('stu1104', 'xiao'), ('stu1106', {'a': 1, 'b': 2}), ('cc', 55)])
{1: 'test', 2: 'test', 3: 'test'}
stu1105 mm
stu1103 aang
stu1104 xiao
stu1106 {'a': 1, 'b': 2}
cc 55
stu1105 mm
stu1103 aang
stu1104 xiao
stu1106 {'a': 1, 'b': 2}
cc 55
|