Add new entry to a dictionary : Dictionary Assignment « Dictionary « Python






Add new entry to a dictionary

Add new entry to a dictionary
 
d2 = {'spam': 2, 'ham': 1, 'eggs': 3}    # make a dictionary

print d2                                       # order is scrambled

d2['ham'] = ['grill', 'bake', 'fry']      # change entry

del d2['eggs']                            # delete entry

d2['brunch'] = 'Bacon'                    # add new entry

print d2


           
         
  








Related examples in the same category

1.Dictionary assignmentDictionary assignment
2.Change dictionary entryChange dictionary entry
3.enter all the data for dict3 at the same time