Mega Code Archive

 
Categories / Python Tutorial / Dictionary
 

String Formatting with Dictionaries

After the % character, you add a key enclosed in parentheses, which is followed by the other specifier elements:  phonebook = {'A': '1', 'B': '2', 'C': '3'} print "C's phone number is %(C)s." % phonebook