python dict add value code example
Example 1: add item to python dictionary
data = dict()
data['key'] = value
Example 2: add value to dictionary python
dict[key] = value
Example 3: append dictionary python
>>> d1 = {1: 1, 2: 2}
>>> d2 = {2: 'ha!', 3: 3}
>>> d1.update(d2)
>>> d1
{1: 1, 2: 'ha!', 3: 3}
Example 4: Python dict add item
# This automatically creates a new element where
# Your key = key, The value you want to input = value
dictionary_name[key] = value
Example 5: python dict append value
default_data = {'item1': 1,
'item2': 2,
}
default_data.update({'item3': 3})
# or
default_data['item3'] = 3