Dictionary get value : Dictionary get « Dictionary « Python






Dictionary get value

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')
           
       








Related examples in the same category

1.Dictionary get: default valueDictionary get: default value
2.Dictionary: Get value by keyDictionary: Get value by key