Python Dictionary Has_key() Method



Python dictionary process has_key() arrivals true if an agreed key is accessible in the dictionary, or else it revisits a false. In Python Dictionary, has_key() technique homecomings true if specified input is present in the glossary, else proceed false. Parameters: key – This is the key to be looked at in the dictionary.


Following is the syntax for the has_key() method:



  • key - This is the Key to be searched in the dictionary.

Return Value

This method returns true if a given key is available in the dictionary, otherwise, it returns a false.


The following example shows the usage of the has_key() method.


dict = {'Name': 'Zara', 'Age': 7}
print "Value : %s" %  dict.has_key('Age')
print "Value : %s" %  dict.has_key('Sex')

When we run the above program, it produces the following result:

Value : True
Value : False

Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.