This class method return a value for the given key. If key is not available then return returns default value None.
dict.get(key, default=None)
Here is the detail of parameters:
key: Key to be searched in the dictionary.
default: Value to be returned in case key does not exist.
#!/usr/bin/python dict = {'Name': 'Zara', 'Age': 7} print "Value : %s" % dict.get('Age') print "Value : %s" % dict.get('Sex', "Never")
This produces following result:
Value : 7 Value : Never
Advertisement