Categories

Dec 19, 2019 in Python

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

1 Answer

Dec 19, 2019

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

Madanswer
Dec 19, 2019 in Python
Apr 3 in Data Handling
Oct 18, 2019 in C Sharp (C#)
...