This article describes how to use the dictionary dict to determine whether a specified key value exists. The example shows how to use has_key and in to determine whether a specified key value exists in python, this document describes how to use the dictionary dict to determine whether a specified key value exists in python. Share it with you for your reference. The details are as follows:
There are two methods in python to determine whether a specified key value exists. one is to determine whether a key value exists through the has_key method of the dictionary object, and the other is to use the in method. The following is a detailed example.
D = {'site': 'http: // www.jb51.net', 'name': 'job51 ', 'Is _ good': 'yes'} # Method 1: through has_keyprint d. has_key ('site') # Method 2: Use inprint 'body' in d. keys ()
I hope this article will help you with Python programming.