Python dictionary (Dictionary) update () method

Original connection: https: //www.runoob.com/python/att-dictionary-update.html

 

Python dictionary (dictionary) update () function to the dictionary dict2 key / value pairs to update dict inside.

Means that the key to update a dictionary to another dictionary.

Example:

dict = {'Name": 'Zara', 'Age':7}

dict2 ={ 'Sex': 'female' }

dict.update(dict2)

print "Value: %s" % dict

Output:

Value: {'Age': 7, 'Name': 'Zara', 'Sex': 'female' }

 

Note: the same key will have to directly replace the value of the update:

a = {1: 2, 2: 2}

b = {1: 1, 3: 3}

b.update(a)

print (b)

Output:

{1: 2, 2: 2, 3: 3}

 

return value:

This method does not have any return value.

Guess you like

Origin www.cnblogs.com/elitphil/p/11824304.html