DEV Community

I'm Just a Guy with a Computer
I'm Just a Guy with a Computer

Posted on

Checking whether a Key or Value Exists in a Dictionary.

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
>>> 
Enter fullscreen mode Exit fullscreen mode

Note: if a Value or key doesn't exist in a dictionay it returns false.

Top comments (0)

The best way to debug slow web pages cover image

The best way to debug slow web pages

Tools like Page Speed Insights and Google Lighthouse are great for providing advice for front end performance issues. But what these tools can’t do, is evaluate performance across your entire stack of distributed services and applications.

Watch video