in Python by
Q:
How Do You Check The Presence Of A Key In A Dictionary?

▼ Show 1 Answer

0 votes
by

We can use Python’s “in” operator to test the presence of a key inside a dict object.

>>> site_stats = {'site': 'tecbeamers.com', 'traffic': 10000, "type": "organic"}

>>> 'site' in site_stats

True

>>> 'traffic' in site_stats

True

>>> "type" in site_stats

True

Earlier, Python also provided the has_key() method which got deprecated.

Python
Learn More with Madanswer

Related questions

0 votes
asked Dec 19, 2019 in Python by sharadyadav1986
...