Add a new item to a dictionary in Python

The Solution to Add a new item to a dictionary in Python is


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.

~ Answered on 2011-06-20 19:08:11


Most Viewed Questions: