Python merges two dictionaries, and python merges two dictionaries.
Two Methods: update () and items ()
In [14]: aOut [14]: {'A': 1, 'B': 2, 'C': 3} In [15]: c = {'D': 4} In [16]:. update (c) In [17]: aOut [17]: {'A': 1, 'B': 2, 'C': 3, 'D ': 4} In [18]: a = {'A': 1} In [19]: aOut [19]: {'A': 1} In [20]: cOut [20]: {'D': 4} In [21]:. items () + c. items () Out [21]: [('A', 1), ('D', 4)] In [22]: dict (. items () + c. items () Out [22]: {'A': 1, 'D': 4}
In [29]: z = a. update (B) In [30]: z
It is not allowed to assign values directly to new variables, so z gets a null value. here we need to look at the update usage,
See http://www.tutorialspoint.com/python/dictionary_update.htm
This function does not return any value, orz, so there is no value
It can also be used to update the value in the dictionary.
In [35]:. update ({'A': 2}) In [36]: aOut [36]: {'A': 2, 'C': 3} In [37]:. update ({'A': 3, 'D': 'D'}) In [38]: aOut [38]: {'A': 3, 'C ': 3, 'D': 'D '}