0 votes
in Python by
How Do You Check The Presence Of A Key In A Dictionary?

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.

Related questions

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