KnowledgeBoat Logo

Computer Science

Can you check for a value inside a dictionary using in operator? How will you check for a value inside a dictionary using in operator ?

Python Dictionaries

8 Likes

Answer

We cannot directly check for a value inside a dictionary using in operator since in operator searches for a key in a dictionary. We can use values() function along with in operator to check for a value in dictionary as shown below:

>>> d = {1: 'a' , 2:'b'}
>>> 'b' in d.values()
Output

True

Answered By

4 Likes


Related Questions