get value from dictionary with default value : get « Dictionary « Python Tutorial






d2 = {'spam': 2, 'ham': 1, 'eggs': 3}         # Make a dictionary

print d2.get('spam' )                           # A key that is there
print d2.get('toast')                           # A key that is missing
print d2.get('toast', 88)








8.10.get
8.10.1.Get value by key
8.10.2.get value from dictionary with default value