About Dictionary
..... Adding new key-value pair to dictionary
$ menu = {} # Empty dictionary
$ menu['Chicken Alfredo'] = 14.50
$ print menu['Chicken Alfredo']
$ print "There are " + str(len(menu)) + " items on the menu."
There are 1 items on the menu.
.....Removed from a dictionary
$ del dict_name[key_name]
$ menu = {} # Empty dictionary
$ menu['Chicken Alfredo'] = 14.50
$ print menu['Chicken Alfredo']
$ print "There are " + str(len(menu)) + " items on the menu."
There are 1 items on the menu.
.....Removed from a dictionary
$ del dict_name[key_name]
Comments
Post a Comment