in Python by
Q:
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.

Click here to read more about Python
Click here to read more about Insurance

Related questions

0 votes
asked Dec 19, 2019 in Python by sharadyadav1986
0 votes
asked Aug 30, 2020 in Python by sharadyadav1986
0 votes
asked Jan 11 in Python by SakshiSharma
+1 vote
asked May 14, 2019 in Machine Learning by Derya
0 votes
asked May 17, 2019 in Other by Derya
...