While Using Python Dictionary DataStructure (which contains key-value pair) if i want to retrieve some value from my Dictionary i have two options d[\'\'] and g.get(\'key
They both behave the same if the key exists. But if the key is not found d['key']
will raise a KeyError
exception, whereas d.get('key')
will return None
. You can also supply a second argument to the get method which will be returned on a not-found condition: d.get('key', '')
will return a null string if the key is not found.