Python dictionary get() method
Python Dictionary get() Method
Description
Python The dictionary method get() returns the value for a given key. If the key is not available, it returns the default value of None.
Syntax
The following is the syntax of the get() method:
dict.get(key, default = None)
Parameters
- key − This is the key to search for in the dictionary.
-
default − The value to return if the key does not exist.
Return Value
This method returns the value for the given key. If the key is not available, the default value of None is returned.
Example
The following example shows the usage of the fromkeys() method.
dict = {'Name': 'Zabra', 'Age': 7}
print "Value : %s" % dict.get('Age')
print "Value : %s" % dict.get('Education', "Never")
When we run the above program, we get the following output −
Value : 7
Value : Never