Skip to content

Computer Science · Ch 10 — Tuples and Dictionaries

Membership

10.9.1

Membership

The membership operator in checks whether a key is present in the dictionary. It returns True if the key exists, else it returns False:

>>> marks = {'Anita': 95, 'Bala': 89, 'Chetan': 92, 'Divya': 85}
>>> 'Chetan' in marks
True

The not in operator does the opposite — it returns True if the key is not present in the dictionary, else it returns False:

>>> marks = {'Anita': 95, 'Bala': 89, 'Chetan': 92, 'Divya': 85}
>>> 'Chetan' not in marks
False
``` …