d = {'key':'value'} print(d) # {'key': 'value'} d['mynewkey'] = 'mynewvalue' print(d) # {'mynewkey': 'mynewvalue', 'key': 'value'}
dict[key] = value
d={'a': 1,'b':2,'c':3} d['d']=100 # to add keys and values in dicionary
# 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}
a_dictonary = {} a_dictonary.update({"Key": "Value"})
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)