In Python, how to check whether a key already exists in a dict?

How to check whether a key already exists in a dict in Python since version 2.6?

If d is a dict(), you can directly test whether a key k is in d in Python by the in keyword like

if k in d:
  ..

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *