Method Name:
get
Method Signature:
get(dict_key[,default_value])
Method Overview:
Returns the value associated with a key in the python dictionary object.
Parameters:
dict_key – The key for which the value needs to be found in the dictionary.
default_value – This is an optional parameter. If the default value is specified it will be returned when a key is not found in the dictionary object. If this parameter is not specified and the key is not found in the dictionary the get() method will return None.
Exception Handling:
This method will not raise a KeyError when the specified key is not found in the dictionary. Refer to the default_value parameter above.
Example 1:
# Example Python program that retrieves # Create a Python dictionary # Populate the dictionary # Retrieve the value corresponding to the |
Output:
Liverpool Arsenal None |
Example 2:
# Example Python program that accesses print(leagues.get(5)); |
Output:
Florida Cup |