Mega Code Archive

 
Categories / Python Tutorial / Dictionary
 

Creating, accessing and modifying a dictionary

emptyDictionary = {} print emptyDictionary grades = { "A": 87, "B": 76, "C": 92, "D": 89 } print "\nAll grades:", grades print grades[ "A" ] grades[ "A" ] = 90 print "A's new grade:", grades[ "A" ] # add to an existing dictionary grades[ "B" ] = 93 print "\nDictionary grades after modification:" print grades # delete entry from dictionary del grades[ "C" ] print "\nDictionary grades after deletion:" print grades