练习12
dic = {'太白':{'name': '太白','age': 25, 'sex': '男',},
'name_list': ['王双','韩蕾','何青松',],
}
dic = {'name': '太白', 'age': 18, 'sex': '男', 'job': 'IT'}
dic['sex'] = '男'
dic['name'] = 'alex'
setdefault 有此key则不做任何操作但是给我返回对应的值,无此key则添加.
dic.setdefault('sex')
dic.setdefault('hobby','讲课')
dic.setdefault('name','alex')
print(dic.setdefault('name'))
print(dic)
print(dic.pop('name'))
print(dic.pop('name1',None))
print(dic.pop('name1','没有此键....'))
print(dic)
dic.clear()
print(dic)
print(dic.popitem())
print(dic)
del
del dic['name']
del dic
print(dic)
dic['age'] = 25
print(dic)
dic = {"name":"jin","age":18,"sex":"male"}
dic2 = {"name":"alex","weight":75,'ssex':'男'}
dic.update(dic2)
print(dic)
print(dic2)
dic.update(a='666',b='222',name='taibai')
print(dic)
print(dic['name'])
print(dic['name1'])
print(bool(dic.get('name')))
print(bool(dic.get('name1')))
print(dic.get('name1','没有此键。。。。'))
dic.keys()
print(dic.keys(),type(dic.keys()))
print(dic.values(),type(dic.values()))
l1 = list(dic.keys())
l2 = list(dic.values())
print(l1)
print(l2)
for key in dic.keys():
print(key)
for values in dic.values():
print(values)
dic.values()
print(dic.values())
print(list(dic.values()))
dic.items()
print(list(dic.items()))
for tuple in dic.items():
print(tuple)
a,b = 10,20
print(a,b)
a,b = [10,20]
print(a,b)
a,b = [(1,2),(3,4)]
print(a,b)
print(type(a))
a = 10
b = 20
a,b = b,a
print(a,b)
for i in dic.items():
'''
i = ('name', '太白')
i = ('age', 18)
....
'''
print(i)
for k,v in dic.items():
'''
k,v = ('name', '太白')
k,v = ('age', 18)
....
'''
print(k,v)
for i in dic:
print(i)
dict
print(len(dic))