I want to add an item in an existing dictionary in python For example, this is my dictionary.

default_data = {
            'item1': 1,
            'item2': 2,
}

I want to add a new item such that.

default_data = default_data + {'item3':3}

How can I achieve this?

Best Answer


default_data['item3'] = 3

Easy as py.

Another possible solution.

default_data.update({'item3': 3})

which is nice if you want to insert multiple items at once.