This article mainly introduces Python to judge the existence of the specified key value through the dictionary Dict method, example analysis of Python using Has_key and in the judgement of the existence of the specified key value is very practical value, the need for friends can refer to the
This example describes how Python can determine whether a specified key value exists through a dictionary dict. Share to everyone for your reference. Specifically as follows:
There are two ways in Python to determine whether a specified key value exists, one that is has_key by the method of the Dictionary object, the other is through the in method, and the following is a detailed example.
?
1 2 3 4 5 |
d={' site ': ' http://www.jb51.net ', ' name ': ' jb51 ', ' is_good ': ' Yes '} #方法1: Through Has_key print d.has_key (' site ') #方法2: through in print ' body ' in D.keys () |
I hope this article will help you with your Python programming.