append function for dictionary in python code example
Example 1: Python dictionary append
d1 = {
"1" : 1,
"2" : 2,
"3" : 3
}
d1["4"] = 4
print(d1)
Example 2: how to append to a dictionary in python
d = {'a': 1, 'b': 2}
print(d)
d['a'] = 100
d['c'] = 3
d['d'] = 4
print(d)
Example 3: python dict append
default_data = {'item1': 1,
'item2': 2,
}
default_data.update({'item3': 3})
default_data['item3'] = 3
Example 4: dictionary append value python
d = {1:2}
d.update({2: 4})
print(d)
Example 5: append dictionary python
>>> d1 = {1: 1, 2: 2}
>>> d2 = {2: 'ha!', 3: 3}
>>> d1.update(d2)
>>> d1
{1: 1, 2: 'ha!', 3: 3}