CBSE Class 11 Computer Science Question 67 of 112

Dictionaries — Question 7

Back to all questions
7
Question

Question 7

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 ?

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