Mega Code Archive

 
Categories / Python / Dictionary
 

Dictionary get value

d = {} #Not so with get: print d.get('name') #You may supply your own "default" value, which is then used instead of None: print d.get('name', 'N/A') # If the key is there, get works like ordinary dictionary lookup: d['name'] = 'Eric' print d.get('name')