1 a={‘a‘:1,‘b‘:2,‘c‘:3}
2 b= {‘aa‘:11,‘bb‘:22,‘cc‘:33}
3 dict(a.items()+b.items())
4 # 结果:
5 {‘a‘: 1, ‘aa‘: 11, ‘c‘: 3, ‘b‘: 2, ‘bb‘: 22, ‘cc‘: 33}
1 a={‘a‘:1,‘b‘:2,‘c‘:3}
2 b= {‘aa‘:11,‘bb‘:22,‘cc‘:33}
3 c={}
4 c.update(a)
5 c.update(b)
6 print(c)
7 # 结果:
8 {‘a‘: 1, ‘aa‘: 11, ‘c‘: 3, ‘b‘: 2, ‘bb‘: 22, ‘cc‘: 33}
1 a={‘a‘:1,‘b‘:2,‘c‘:3}
2 b= {‘aa‘:11,‘bb‘:22,‘cc‘:33}
3 dict(a,**b)
4 # 结果:
5 {‘a‘: 1, ‘aa‘: 11, ‘c‘: 3, ‘b‘: 2, ‘bb‘: 22, ‘cc‘: 33}
1 a={‘a‘:1,‘b‘:2,‘c‘:3}
2 b= {‘aa‘:11,‘bb‘:22,‘cc‘:33}
3 c = {}
4 for k,v in a.items():
5 c[k] = v
6 for k,v in v.items():
7 c[k] = v
8 print(c)
9 # 结果:
10 {‘a‘: 1, ‘aa‘: 11, ‘c‘: 3, ‘b‘: 2, ‘bb‘: 22, ‘cc‘: 33}
1 dict = {‘Name‘: ‘Runoob‘, ‘Age‘: 7}
2 for i in dict:
3 print(i)
1 dict = {‘Name‘: ‘Runoob‘, ‘Age‘: 7}
2 for i in dict.values()
3 print(i)
1 dict.items()
2 for key,value in dict.items():
3 print(key)
4 print(value)
原文:https://www.cnblogs.com/crazywh/p/13674526.html