d = {'key':'value'} print(d) # {'key': 'value'} d['mynewkey'] = 'mynewvalue' print(d) # {'mynewkey': 'mynewvalue', 'key': 'value'}
dict[key] = value
# Basic syntax: dictionary['new_key'] = value # Example: d = {'a': 1, 'b': 5} # Define dictionary d['c'] = 37 # Add a new key to the dictionary print(d) --> {'a': 1, 'b': 5, 'c': 37}
>>> d1 = {1: 1, 2: 2} >>> d2 = {2: 'ha!', 3: 3} >>> d1.update(d2) >>> d1 {1: 1, 2: 'ha!', 3: 3}
d = {'key': 'value'} print(d) # {'key': 'value'} d['mynewkey'] = 'mynewvalue' print(d) # {'key': 'value', 'mynewkey': 'mynewvalue'}
dict = {'key1':'addme', 'key2':'fill_me'} print("Current Dict is: ", dict) # using the subscript notation # Dictionary_Name[New_Key_Name] = New_Key_Value dict['key2'] = 'for' dict['key3'] = 'newtask' print("Updated Dict is: ", dict)