In this article you will learn how to check whether a key or Value Exists in a Dictionay in python by use of in or not Operators.
Enter the following code into the interactive shell and see the output:
>>> spam = {'name':'vincent','age':24}
>>> 'name' in spam.keys()
True
>>> 24 in spam.values()
True
>>> 'age' in spam.keys()
True
>>> 'color' in spam
False
>>>
Note: if a Value or key doesn't exist in a dictionay it returns false.
Top comments (0)